简体   繁体   中英

Should I use `git pull --rebase origin master` or `git rebase origin/master` if the local branch won't be used anymore?

From my understanding,

git pull --rebase origin master

is equivalent to

git fetch origin
git rebase origin/master

So if we simply just do git rebase origin/master instead of git pull --rebase origin master , is the only difference that any new commits from the remote master branch won't make it to our local branch? Or are there edge cases that I need to be aware of?

Hypothetically, if all we want to do is rebase and no longer work with the current local branch, is there ever a need to incorporate the git fetch origin step?

Stack Overflow is not really suited to "should" or "need" questions. What you do is something you must decide. What we can do is clarify for you what your code means. Let's say this is the initial situation:

A -- B -- C -- D <-- master on the remote

A -- B -- C <-- origin/master on your computer
 \
  X -- Y <-- your local branch

If you are on your local branch and you now rebase onto origin/master , you'll get this:

A -- B -- C -- D <-- master on the remote

A -- B -- C <-- origin/master on your computer
           \
            X' -- Y' <-- your local branch

If you had said git fetch and then rebase onto origin/master , you'll get this:

A -- B -- C -- D <-- master on the remote

A -- B -- C -- D <-- origin/master on your computer
                \
                 X' -- Y' <-- your local branch

Which is better? Only you know. It depends on why you are rebasing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM