How to redirect other tracking branches in git?

We work with a model of one remote repository that we all use. We are deploying new features and reintegrating into the branch. Our workflow is that we must integrate from the trunk into our work branches when other functions are integrated into the trunk.

Thus, we are not uncommon:

(branch) $ git commit -a -m"blah blah blah" (branch) $ git fetch # origin/trunk is updated (branch) $ git checkout trunk (trunk) $ git pull # trunk is fast-forwarded to current version of origin/trunk. (trunk) $ git checkout branch (branch) $ git merge trunk (branch) $ git push 

I don’t like the git checkout trunk / git pull / git checkout branch "loop. It usually works with Visual Studio, complaining that all my files and projects have been modified on disk, and if they reload them. For both checks. And pull And merging: Merging is inevitable, but because of how git works, it must be able to fast forward on the trunk without requiring it to be checked.

But I do not know this command, and my google-foo did not help me with this. Does anyone know how?

+22
git
Feb 28 2018-11-21T00:
source share
4 answers

Do you really need to update the local trunk branch?

Just fetch origin/trunk and merge it is directly in the branch you are working on.
And this is Mark Longair advice: git: fetch and merge , dont pull .




Oliver mentions in his answer (above):

 git fetch upstream trunk:trunk 

How does he comment :

you can skip merging and just fast forward using single line.

It redirects the local trunk branch to the remote HEAD branch.

See details on git page : update local branch without checking? "

+19
Feb 28 2018-11-21T00:
source share

I think the easiest way to avoid the git checkout trunk , git pull , git checkout branch loop is to use this answer :

 git fetch upstream trunk:trunk 

This does exactly what you want - redirect your local trunk branch to the remote HEAD branch.

+27
Feb 06 '14 at 11:14
source share

I agree with VonC's answer , but thought it would be interesting to answer the question "How to quickly forward master if you are on a different branch?" anyway. I don’t think there is a way to do this simply using china commands, but this script does the job (obviously, you would like to change master to trunk in your case):

 #!/bin/sh BRANCH=master NEWER=origin/master if [ x"$(git symbolic-ref HEAD)" = x"refs/heads/$BRANCH" ] then echo "This doesn't make sense if you're already on the branch '$BRANCH'" echo "Just run: git merge $NEWER" exit 1 fi BRANCH_HASH=$(git rev-parse $BRANCH) NEWER_HASH=$(git rev-parse $NEWER) MERGE_BASE=$(git merge-base $BRANCH_HASH $NEWER_HASH) if [ "$MERGE_BASE" = "$BRANCH_HASH" ] then git update-ref "refs/heads/$BRANCH" "$NEWER_HASH" "$BRANCH_HASH" else echo "$BRANCH can't be fast-forwarded to $NEWER" exit 1 fi 

Update 2012-10-20: this script was just a quick example; for a script that does the same, but to merge any arbitrary commit-ish into a local branch (as long as the merge is fast forward), see Jefromi's answer to a similar question .

+8
Feb 28 '11 at 10:12
source share

Try the following:

 $ git pull trunk branch 
-2
Feb 28 2018-11-21T00:
source share



All Articles