Avoiding Git Merge Commits with branch.branchname.rebase = true

If you have local changes in your Git repo and pull in new changes from your remote repository, Git will per default create a merge commit for the pulled changes. This can clutter your history with unnecessary commits.

To rebase your local changes on top of the pulled changes, you can use:

git pull --rebase

To activate this for all new branches.

git config --global branch.autosetuprebase always

To update existing branches in your Git repo use the command:

git config branch.<name>.rebase true

Not everyone likes rebase. Here is a little summary why Linus Torvalds doesn’t like rebasing: http://kerneltrap.org/Linux/Git_Management.

About Lars Vogel

Lars Vogel is the founder and CEO of the vogella GmbH and works as Eclipse and Android consultant, trainer and book author. He is a regular speaker at international conferences, He is the primary author of vogella.com. With more than one million visitors per month this website is one of the central sources for Java, Eclipse and Android programming information.
This entry was posted in Other and tagged . Bookmark the permalink.

2 Responses to Avoiding Git Merge Commits with branch.branchname.rebase = true

  1. Ans says:

    But if I have local changes and i try to use git pull, it says you can’t, first commit your changes to local repository;
    Is that a normal behavior? because having this you described problem will never occur to me;

  2. Lars Vogel says:

    @Ans: This setting will prevent that you get a merge commit on top of your changes with the changed pulled in from repo. You will have one commit less in this case.

Comments are closed.