Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleted local master branch

Tags:

git

github

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.

like image 273
Eliezer Wohl Avatar asked Nov 30 '15 19:11

Eliezer Wohl


People also ask

Can I delete local master branch git?

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 local branch in git?

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.

What does it mean to delete a local branch?

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.

How do I delete the master branch?

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.

How do I delete a remote branch in Git?

To delete a remote branch, you need to use the "git push" command: $ git push origin --delete <remote-branch-name>

What is the master branch in Git?

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


3 Answers

git branch master origin/master

like image 119
Stefan Kendall Avatar answered Oct 28 '22 22:10

Stefan Kendall


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
like image 42
11thdimension Avatar answered Oct 28 '22 20:10

11thdimension


You can simple do,

git checkout master

Git will pull master branch if you don't have it in local.

like image 30
Freddy Avatar answered Oct 28 '22 22:10

Freddy