I was sloppy and was deleting a whole bunch of local branchs, instead of doing them one by one after each one was done, and I accidentally deleted my local master branch on git. The project is still up at github. So how do I resolve this issue? If it helps I'm using terminal on a mac.
A: Git doesn't allow you to delete a local branch if you have the branch checked out. If you're having trouble deleting a Git branch, make sure you Git checkout a branch other than the one you want to delete.
What Happens If I Delete a Git Branch? When you delete a branch in Git, you don't delete the commits themselves. That's right: The commits are still there, and you might be able to recover them.
That means you no longer need to keep and use that branch, so it is a common best practice to delete it so it doesn't clutter up your code. Local branches are branches on your local machine and do not affect any remote branches. The command to delete a local branch in Git is: git branch is the command to delete a branch locally.
Choose main branch as protected and set rules for allowance of merging, pushing and owner approval and save your changes. Press the Unprotect Button for master. Now you are able to delete the master branch.
To delete a remote branch, you need to use the "git push" command: $ git push origin --delete <remote-branch-name>
Master branch is not a special branch, it can easily be created just as any other branch. git branch master ## creating master branch git checkout master ## switching to master branch git branch -u origin/master ## setting up remote tracking branch
git branch master origin/master
Master branch is not a special branch, it can easily be created just as any other branch.
git branch master ## creating master branch
git checkout master ## switching to master branch
git branch -u origin/master ## setting up remote tracking branch
or
git branch master ## creating master branch
git branch -u origin/master master ## setting up remote tracking without switching
git checkout master ## switching out to master
or all in one
git checkout -b master origin/master ## create, set up tracking, switch
You can simple do,
git checkout master
Git will pull master branch if you don't have it in local.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With