Reputation: 2016
I am switching over to GitHub from a different git provider. I pulled all branches to my local with
for remote in `git branch -r`; do git branch --track $remote; done
but instead of getting branch named name
I got them named origin/name
so now I need to rename them to be just name
.
Any ideas how to batch rename them? Or maybe just pull them with the right name would help too.
Upvotes: 1
Views: 240
Reputation: 60625
for remote in `git branch -r`; do git branch --track $remote; done
Remote-tracking branches are conventionally referred to with their remote name as the first element, so git branch -r
is showing you e.g. origin/master
, origin/release
and so forth. But your own branches aren't conventionally referred to with a prefix.
The full spelling of the remote-tracking branch origin/master
is refs/remotes/origin/master
, and what the branch command (and any other command that takes branch and tag names that don't start ref/
) is doing is inferring what you're after by how you use it.
So for git branch --track origin/master
you're using it as a local branch name. What you probably want is
for remote in `git branch -r`; do git branch --track ${remote#*/} $remote; done
The #*/
in ${remote#*/}
is part of the shell's parameter expansion features, find the "parameter expansion" in any shell docs, google 'man sh' and find that section. It strips the shortest leading string matching the pattern */
from the expansion, so it'll strip origin/
here.
Upvotes: 3
Reputation: 5755
If you have 2 repositories,
The local is called local
And the remote is called origin
In the master branch of local, you can delete all the branches that start with "origin":
$ git branch -D origin/name_of_branch
$ git branch -D origin name_of_other_branch
etc.
Then,
$ git fetch origin
will allow local to work with the latest version of origin. For each branch you want to pull down from origin:
$ git checkout -b name_of_branch
$ git rebase origin/name_of_branch
This will create branch "name_of_branch" in local and pull the changes from origin into that branch.
You also want to make sure that there are no conflicting changes in "origin". If there are, post the issue and we can discuss it in a separate question.
Upvotes: -1