How to fast-forward a branch to head?
I switch to master after develop on a branch for a long time. The log shows:
Your branch is behind ‘origin/master’ by 167 commits, and can be fast-forwarded.
How to manage large data files with GitHub? Naive Git setup, Is it possible to untrack files which are listed on my .gitignore? Putting git hooks into repository Git clean inside ignored folders Switch branches with tortoisegit git diff extended header `index` 2nd hash corresponds to what
git checkout HEAD
It has no effect. This is cause because that I have checkout out an intermediate commit on master.
How to make master stay on head?
7 Solutions collect form web for “How to fast-forward a branch to head?”
git checkout master git pull origin
will fetch and merge the
origin/master branch (you may just say
git pull as origin is the default).
git merge origin/master. If you want to be sure that it only does a fast-forward, you can say
git merge --ff-only origin/master.
In your situation,
git rebase would also do the trick. Since you have no changes that master doesn’t have, git will just fast-forward. If you are working with a rebase workflow, that might be more advisable, as you wouldn’t end up with a merge commit if you mess up.
username@workstation:~/work$ git status # On branch master # Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded. # (use "git pull" to update your local branch) # nothing to commit, working directory clean username@workstation:~/work$ git rebase First, rewinding head to replay your work on top of it... Fast-forwarded master to refs/remotes/origin/master. # On branch master nothing to commit, working directory clean
git checkout master git pull
should do the job.
You will get the “Your branch is behind” message every time when you work on a branch different than master, someone does changes to master and you git pull.
(branch) $ //hack hack hack, while someone push the changes to origin/master (branch) $ git pull
now the origin/master reference is pulled, but your master is not merged with it
(branch) $ git checkout master (master) $
now master is behind origin/master and can be fast forwarded
this will pull and merge (so merge also newer commits to origin/master) (master) $ git pull this will just merge what you have already pulled (master) $ git merge origin/master
now your master and origin/master are in sync
If you are standing on a different branch and want to checkout the newest version of master you can also do
git checkout -B master origin/master
No complexities required
just stand at your branch and do a git pull it worked for me
Or, as a second try git pull origin master only in case if you are unlucky with the first command
Move your brunch pointer to the HEAD:
git branch -f master
master already exists, so git will not allow you to overwrite it, unless you use…
-f (this argument stands for
Or you can use rebase:
git rebase HEAD master
Do it on your own risk 😉