Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git always merge without a fast-forward, except for when pulling?

Is there a way to have git always merge without a fast-forward, except for when pulling?

Following a nice git-flow, I like keeping my branch history (easier to remove features, etc later on), so I have set my config to never fast-forward when merging, like so:

git config --global merge.ff false

However, whenever I update my current branch/pull from the remote, it creates a merge commit... which is really gross, especially for forking other projects on GitHub.

Is there anyway to make a git pull always fast-forward? Unfortunately, I tried doing:

git pull --ff-only upstream master

... only to watch it spit out an error:

fatal: You cannot combine --no-ff with --ff-only.

I'm really tired of seeing this:

Gross: a "git pull" merge commit

like image 647
Rican7 Avatar asked Nov 28 '12 03:11

Rican7


2 Answers

You can try this:

git pull --rebase upstream master

This will rebase your commits on top of upstream commits.

Here is an illustration of what it does.

Your local repository:

* bbbbbbb (HEAD, master) My changes.
* aaaaaaa Initial commit.

Upstream repository:

* ccccccc (upstream/master) Their changes.
* aaaaaaa Initial commit.

After git pull --rebase upstream master:

* bbbbbbb (HEAD, master) My changes.
* ccccccc (upstream/master) Their changes.
* aaaaaaa Initial commit.
like image 165
htanata Avatar answered Oct 13 '22 20:10

htanata


I'd suggest you to work in a separate branch and keep rebasing onto the remote branch instead of merging.

Change:

$ git checkout -b my-topic-branch
$ (work work work)
$ git commit
$ git checkout master
$ git pull origin master
$ git merge my-topic-branch

By:

$ git checkout -b my-topic-branch
$ (work work work)
$ git commit
$ git fetch origin
$ git rebase origin/master
$ git checkout master
$ git merge my-topic-branch

If that combination of configurations don't work, I think you're left with that.

like image 25
mgarciaisaia Avatar answered Oct 13 '22 19:10

mgarciaisaia