Git Pull vs Git Rebase

后端 未结 3 1034
北荒
北荒 2021-01-29 20:31

I\'m a noob in Git, and trying to learn the difference between git pull vs git rebase. Can someone provide an example when to use which option since I

3条回答
  •  臣服心动
    2021-01-29 21:01

    git pull and git rebase are not interchangeable, but they are closely connected.

    git pull fetches the latest changes of the current branch from a remote and applies those changes to your local copy of the branch. Generally this is done by merging, i.e. the local changes are merged into the remote changes. So git pull is similar to git fetch & git merge.

    Rebasing is an alternative to merging. Instead of creating a new commit that combines the two branches, it moves the commits of one of the branches on top of the other.

    You can pull using rebase instead of merge (git pull --rebase). The local changes you made will be rebased on top of the remote changes, instead of being merged with the remote changes.

    Atlassian has some excellent documentation on merging vs. rebasing.

提交回复
热议问题