I have a project with multiple branches. I've been pushing them to GitHub, and now that someone else is working on the project I need to pull their branches from GitHub. It works fine in master. But say that someone created a branch xyz
. How can I pull branch xyz
from GitHub and merge it into branch xyz
on my localhost
?
I actually have my answer here: Push and pull branches in Git
But I get an error "! [rejected]" and something about "non fast forward".
Any suggestions?
I am not sure I fully understand the problem, but pulling an existing branch is done like this (at least it works for me :)
This is assuming that your local branch is created off of the origin/BRANCH.
You could pull a branch to a branch with the following commands.
When you are on the master branch you also could first checkout a branch like:
This creates a new branch, "xyz", from the master and directly checks it out.
Then you do:
This pulls the new branch to your local
xyz
branch.git fetch
will grab the latest list of branches.Now you can
git checkout MyNewBranch
Done :)
For more info see docs: git fetch
I did
Instead of
As suggested by @innaM. When I used the upstream version, it said 'fatal: Not a valid object name: 'upstream/remote_branch_name''. I did not do
git fetch origin
as a comment suggested, but instead simply replacedupstream
withorigin
. I guess they are equivalent.This helped me to get remote branch before merging it into other:
Simply put, If you want to pull from GitHub the branch
the_branch_I_want
: