merge specific - Git pull a certain branch from GitHub

remote example (9)

I am not sure I fully understand the problem, but pulling an existing branch is done like this (at least it works for me :)

git pull origin BRANCH

This is assuming that your local branch is created off of the origin/BRANCH.

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?

You could pull a branch to a branch with the following commands.

git pull {repo} {remotebranchname}:{localbranchname}

git pull origin xyz:xyz

When you are on the master branch you also could first checkout a branch like:

git checkout -b xyz

This creates a new branch, "xyz", from the master and directly checks it out.

Then you do:

git pull origin xyz

This pulls the new branch to your local xyz branch.

The best way is:

git checkout -b <new_branch> <remote repo name>/<new_branch>

you may also do

git pull -r origin master

fix merge conflicts if any

git rebase --continue

-r is for rebase. This will make you branch structure from

        v  master       
          ^ other branch


        v  master       
              ^ other branch

This will lead to a cleaner history. Note: In case you have already pushed your other-branch to origin( or any other remote), you may have to force push your branch after rebase.

git push -f origin other-branch

git pull <gitreponame> <branchname>

Usually if you have only repo assigned to your code then the gitreponame would be origin.

If you are working on two repo's like one is local and another one for remote like you can check repo's list from git remote -v. this shows how many repo's are assigned to your current code.

BranchName should exists into corresponding gitreponame.

you can use following two commands to add or remove repo's

git remote add <gitreponame> <repourl>
git remote remove <gitreponame>

git fetch will grab the latest list of branches.

Now you can git checkout MyNewBranch

Done :)

For more info see docs: git fetch

Simply track your remote branches explicitly and a simple git pull will do just what you want:

git branch -f remote_branch_name origin/remote_branch_name
git checkout remote_branch_name

Or even more fitting in with the GitHub documentation on forking:

git branch -f new_local_branch_name upstream/remote_branch_name

This helped me to get remote branch before merging it into other:

git fetch repo xyz:xyz
git checkout xyz

git reset filename.txt  

Will remove a file named filename.txt from the current index, the "about to be committed" area, without changing anything else.

git merge branch github pull