Rebase and merge setup

By default, when performing git pull, a merge commit will be created if the history of the local branch has diverged from the remote one. However, to avoid all these merge commits, a repository can be configured so that it will default to rebase instead of merging when doing git pull. Several configuration targets related to the option are available as follows:

  • pull.rebase: This configuration, when set to true, will pull to rebase the current branch on top of the fetched one when performing a git pull. It can also be set to preserve so that the local merge commit will not be flattened in the rebase, by passing --preserve-merges to git rebase. The default value is false,as the configuration is not set. To set this option in your local repository, run the following command:
$ git config pull.rebase true  
  • branch.autosetuprebase: When this configuration is set to always, any new branch created with <git branch or git checkout that tracks another branch will be set up to pull to rebase (instead of merge). The valid options are as follows:
    • never: This is set to pull to rebase (default)
    • local: This is set to pull to rebase for local tracked branches
    • remote: This is set to pull to rebase for remote tracked branches
    • always: This is set to pull to rebase for all tracked branches
    • To set this option for all the new branches regardless of tracking remote or local branches, run the following command:
$ git config branch.autosetuprebase always
  • branch.<name>.rebase: This configuration, when set to true, applies only to the <name> branch and tells Git to pull to rebase when performing git pull on the given branch. It can also be set to preserve so that the local merge commit will not be flattened when running git pull. By default, the configuration is not set for any branch. To set the feature/2 branch in the repository to default to rebase, instead of merge, we can run the following command:
$ git config branch.feature/2.rebase true
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.0.192