Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting rid of the repository name prefix from branches

Tags:

git

github

I cloned my entire GitHub repository to a local computer using:

git clone [email protected]:my_account_name/my_repository_name.git

Suppose the branches I had on the remote repository were foo and bar. When I do:

git branch -r

the remote branches stored on my local computer are listed with the names:

origin/foo
origin/bar

(And with git branch -a, they appear with remotes/ further prefixed.) When I work on the branches on my local computer, I want to refer to the branches without the origin/ prefix. For each branch, I can probably do like:

git branch -m origin/foo foo

to rename the branch, but I actually have a lot of branches, and do not want to do it manually one by one. Is there a way to get rid of these origin/ (or remotes/origin/) prefix for multiple remote branches on the local computer at once?

like image 217
sawa Avatar asked Jan 28 '26 04:01

sawa


1 Answers

Just do git checkout foo. That's it.

You're not supposed to rename or work in the origin/* branches, they track the remote repository's state. You don't work in them directly, you create your local copies.

Checking out a branch which doesn't exist locally but does exist remotely creates this branch automatically for you, so just do a checkout but omit the origin/ part.

like image 98
tkausl Avatar answered Jan 29 '26 19:01

tkausl