Git Pull vs Git Rebase

后端 未结 3 1011
北荒
北荒 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:03

    git-pull - Fetch from and integrate with another repository or a local branch GIT PULL

    Basically you are pulling remote branch to your local, example:

    git pull origin master
    

    Will pull master branch into your local repository

    git-rebase - Forward-port local commits to the updated upstream head GIT REBASE

    This one is putting your local changes on top of changes done remotely by other users. For example:

    • You have committed some changes on your local branch for example called SOME-FEATURE
    • Your friend in the meantime was working on other features and he merged his branch into master

    Now you want to see his and your changes on your local branch. So then you checkout master branch:

    git checkout master
    

    then you can pull:

    git pull origin master
    

    and then you go to your branch:

    git checkout SOME-FEATURE
    

    and you can do rebase master to get lastest changes from it and put your branch commits on top:

    git rebase master
    

    I hope now it's a bit more clear for you.

提交回复
热议问题