Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switch current branch in git bare repository

I actually want to remove a branch in the bare repository i am working with, but this task hits a dead end because I cannot switch away from the master repository without a 'work tree' which a bare repository does not have.

When I run git branch -d master the output is:

error: Cannot delete the branch 'master' which you are currently on. 

So I try to switch to another branch called 'develop' by running git checkout develop and the output is:

fatal: This operation must be run in a work tree 
like image 957
Ankur Avatar asked Dec 17 '10 06:12

Ankur


People also ask

How do I change a branch in repository?

You can run repo forall -c 'git checkout branch_name' which will checkout the specified branch for all projects that are declared in your current manifest but if there are projects added/removed between gingerbread and ics (which there are), then you won't get the code for these projects.

Can I switch branch without commit?

when you switch to a branch without committing changes in the old branch, git tries to merge the changes to the files in the new branch. If merging is done without any conflict, swithing branches will be successful and you can see the changes in the new branch.

Which command is used to switch between branches in a repository?

The users need to switch between the branches based on the project work. `git checkout` command is used to switch between the branches before. This command is used to switch between the branches and perform different types of tasks such as restore files, undo changes, etc.


1 Answers

Try this instead of git checkout:

git symbolic-ref HEAD refs/heads/develop 

Then you should be able to delete master.

like image 100
cdhowie Avatar answered Sep 24 '22 14:09

cdhowie