I am working on a branch "branch-A" and using the command git branch
I can see that its the only branch locally.
If I use git branch -a
I can see the remote copy of "remotes/origin/branch-B"
What I want to do is bring branch-B locally, but I don't want to actually check it out... I mean I could do that and then checkout my other branch to go back, but its slightly more painful since I am doing this to lots of repos.
I was thinking some sort of fetch? but I can't figure out how to phrase the command. Is it possible?
So I have:
user@pc> git branch
* branch-A
master
and
user@pc> git branch -a
* branch-A
remotes/origin/branch-B
remotes/origin/branch-A
remotes/origin/master
I want to be able to get:
user@pc> git branch
* branch-A
branch-B
master
If you have a single remote repository, then you can omit all arguments. just need to run git fetch , which will retrieve all branches and updates, and after that, run git checkout <branch> which will create a local copy of the branch because all branches are already loaded in your system.
1 Answer. There is a command that gives you about all tracking branches. And to know about the pull and push configuration per branch you can use the command git remote show origin. and you can use -sb option for seeing the upstream.
You can tell Git to track the newly created remote branch simply by using the -u flag with "git push".
You can do this, one liner very simple.
git fetch <remote> <srcBranch>:<destBranch>
this will avoid to checkout the remote branch.
See this question for more information:
Merge, update, and pull Git branches without using checkouts
I think there's some ambiguity about what "bring branch-B locally" means.
If you see origin/branch-B
then you already have it locally. The commits, the trees they contain, the files they contain... all are already in your local repo. The only thing you don't have is a local branch (branch-B
) tracking the remote branch (origin/branch-B
).
If you don't want to check branch-B
out, then there aren't a lot of reasons to create the local branch. Just about anything you can do with a local branch, you can do with the remote branch reference. e.g.:
git merge origin/branch_B
But if you want one, you can create it:
git branch --set-upstream branch_B origin/branch_B
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