But I get an error "! [rejected]" and something about "non fast forward"
That's because Git can't merge the changes from the branches into your current master. Let's say you've checked out branch master, and you want to merge in the remote branch other-branch. When you do this:
$ git pull origin other-branch
Git is basically doing this:
$ git fetch origin other-branch && git merge other-branch
That is, a pull is just a fetch followed by a merge. However, when pull-ing, Git will only merge other-branch if it can perform a fast-forward merge. A fast-forward merge is a merge in which the head of the branch you are trying to merge into is a direct descendent of the head of the branch you want to merge. For example, if you have this history tree, then merging other-branch would result in a fast-forward merge:
O-O-O-O-O-O
^ ^
master other-branch
However, this would not be a fast-forward merge:
v master
O-O-O
\
\-O-O-O-O
^ other-branch
To solve your problem, first fetch the remote branch:
$ git fetch origin other-branch
Then merge it into your current branch (I'll assume that's master), and fix any merge conflicts:
$ git merge origin/other-branch
# Fix merge conflicts, if they occur
# Add merge conflict fixes
$ git commit # And commit the merge!
Answer from mipadi on Stack OverflowBut I get an error "! [rejected]" and something about "non fast forward"
That's because Git can't merge the changes from the branches into your current master. Let's say you've checked out branch master, and you want to merge in the remote branch other-branch. When you do this:
$ git pull origin other-branch
Git is basically doing this:
$ git fetch origin other-branch && git merge other-branch
That is, a pull is just a fetch followed by a merge. However, when pull-ing, Git will only merge other-branch if it can perform a fast-forward merge. A fast-forward merge is a merge in which the head of the branch you are trying to merge into is a direct descendent of the head of the branch you want to merge. For example, if you have this history tree, then merging other-branch would result in a fast-forward merge:
O-O-O-O-O-O
^ ^
master other-branch
However, this would not be a fast-forward merge:
v master
O-O-O
\
\-O-O-O-O
^ other-branch
To solve your problem, first fetch the remote branch:
$ git fetch origin other-branch
Then merge it into your current branch (I'll assume that's master), and fix any merge conflicts:
$ git merge origin/other-branch
# Fix merge conflicts, if they occur
# Add merge conflict fixes
$ git commit # And commit the merge!
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
The latter is a local operation.
Or even more fitting in with the GitHub documentation on forking:
git branch -f new_local_branch_name upstream/remote_branch_name
using git pull on a branch other than main.
version control - How do I git pull a dev branch? - Drupal Answers
How to overwrite local changes from remote repository?
practical advice on git config pull.rebase true/false?
I sometimes want to run `git pull` for branches other than main/master so I run
`git switch branch-name`
`git pull --rebase`
I for some reason have had this work and I remember a stack overflow post stating that it should work, but today when I pull from my github remote into my local repo it says that the branch is up to date, I check log n its still a few commits behind. My question is why doesn't this work and what is the proper way to git pull for other branches?
Any help is appreciated!
If I do
git clone --recursive --branch 7.x-3.x http://git.drupal.org/project/views.git
and then
git branch -r
I get
origin/4.6.x-1.x
origin/4.7.x-1.x
origin/5.x-1.x
origin/6.x-2.11-security
origin/6.x-2.x
origin/6.x-3.x
origin/7.x-3.x
origin/8.x-3.x
origin/HEAD -> origin/7.x-3.x
origin/d7v3ui
origin/master
I believe you need the recursive flag to get all remotes. Not sure if you did that, but a quick git fetch will update your list of remotes.
git pull origin 7.x-3.x-dev
fatal: Couldn't find remote ref 7.x-3.x-dev
Unexpected end of command stream
I think this is just due to the naming conventions, current dev is HEAD afaik.
git pull origin 7.x-3.x
From http://git.drupal.org/project/views
* branch 7.x-3.x -> FETCH_HEAD
Already up-to-date.
I believe that any branch (not tag) can be considered 'dev' for that drupal version.
Hope this helps.
I'm not a Git expert, but as I understand it all of the releases of the dev branch listed on the project page are made directly to the 7.x-3.x branch. Of course you're free to create your own branches locally for your own needs, but the master-like branch, which includes all of the releases pushed to drupal.org, is always going to be that 7.x-3.x branch.
If you want to switch to one of the tagged releases, use git tag to get a list of all the releases. Then, to check out the 7.x-3.1 release (for example), use git co 7.x-3.1.
If you intend to edit the code for this release, you can then create a new branch (as Git explains) by using git checkout -b mycustombranch.