I messed up the Master Branch and project wont load, how do i make a new master branch? - github

So our Master branch is f*cked how can I delete that master branch and make a new master from my current working branch?
Thanks!
and I always keep getting this change being made. I literally do nothing and this happens. Is the .vs folder supposed to be on Github?
Also, I keep getting changes in the csproj file and cache. What are those? I'm new to GitHub.

Like any other branch:
# First, drop the messed-up branch:
$ git branch -D master
# Create a new master branch from your current branch:
$ git checkout -b master
# Force push it to GitHub:
$ git checkout master
$ git push --force origin master

Related

Git 'There is nothing to compare' main and master are entirely different commit histories

I'm not used to git and I'm starting to learn it but I got stuck in pushing the changes into one branch 'Master'.
In github I see that I have 2 branches: Main and Master, after making my changes and afterward I ran the following commands:
-git add .
-git commit -m 'Commit-text'
-git push origin master
And everything is fine since on github I can see the changes but only in the branch 'Master' while the branch 'Main' doesn't result changed. How can I solve this issue?
You can simply solve this problem by going to Git Bash and renaming your main branch:
$ git branch -M [NAME_BRANCH]
so in your case:
$ git branch -M main
GitHub has recently taken the decision to rename its main branches from master to main. So "master" is expected to fall into disuse in the next few years.
So what I recommend, whenever you start a new project on Git, is to always rename the main branch from the beginning.
So when you push your code, you can safely use only one main branch using the following code: $ git push origin main

How to move an entire branch to the main branch

I have the following branches :
I wish to make my client-rework branch the master branch. I dont want to merge it, I want to entirely replace the master branch with the newest i created. I also dont want the master branch remove, ideally it would be renamed to something like master-old or something. Is this possible or am i asking something dumb here.
you can set your client-rework to be the default branch in setting, tab branches. like in my case below, i set develop as the default branch
First thing master branch is by default protected. You have to remove that from settings, it depends which git flavor you are using. and you should not delete because that is how industry practices work. you may try git checkout master or some other branch
Assuming you are using Github you have to change the default branch first.
After that you need to rename the local client-rework branch to master:
$ git branch -m master master-old
$ git branch -m client-rework master
Now push the branches to origin remote:
$ git push origin HEAD

GitHub feature branch

I have forked a repo with master branch . I have few changes here committed. I have to work a some feature now.how can I create a feature branch with latest from upstream and without the commits made to my master branch in my fork
Very simple actually.
Create the new branch feature, fetch upstream/master and reset feature:
# fetch latest `master` from `upstream` remote
$ git fetch upstream master
# create and checkout new `feature` branch off your current branch (`master`)
$ git checkout -b feature
# reset `feature` branch to `upstream/master`
$ git reset upstream/master --hard

change branch into new master github

When I type "git branch" i get this:
Zachs-MacBook-Pro:stocks1 zachsmith$ git branch
77e98af109bd63630b38c1f1ca3937d43715ddf4
add_bootstrap
add_stock_model
master
stocks_download
temp
* working
working#2(backup)
Does this mean i am on "working" branch of the detached head "77e98af109bd63630b38c1f1ca3937d43715ddf4"?
i want where I am now to become the new master on github, but I am not sure how to do that without merging things. basically I would be happy to just re-write the master with where I currently am.
How can I do this?
Does this mean I am on "working" branch of the detached head "77e98af109bd63630b38c1f1ca3937d43715ddf4"?
No, it just means:
you are on the working branch nammed "working"
there is another branch named "77e98af109bd63630b38c1f1ca3937d43715ddf4" (probably some mishap in the git branch command)
basically I would be happy to just re-write the master with where I currently am.
You can rename the remote master
git branch old_master origin/master
git push origin old_master
And force push your working branch
git push --force origin working:master
You would see a similar approach in "Rename master branch for both local and remote Git repositories".
You have multiple options in order to do that, one is to delete the master branch and rename your working branch as master, but you might know you can be sentenced up to 25 years of jail and death penalty for that.
You can also rename your old master branch and rename your working branch as the new master, or (my favourite way) you can use the -s ours flag so you keep your master intact and you overwrite everything from your working branch:
git checkout working
git merge -s ours master
git checkout master
git merge working
And your master now will match to your working branch.

Messed up my master branch on Github

While contributing to a github project that I had folked. I committed my changes to the master branch of my repo. By mistake I did a pull from the Project's repo. Now while I do a PR from my repo, it includes those changes too. I dont want that to happen, can anyone help?
Just reset your local master and push it back.
$ git checkout master
$ git reset <last_good_commit>
$ git push