Running `git pull --rebase`, what does it rebase against?

Running `git pull --rebase`, what does it rebase against?



I see a lot of examples of:



git pull --rebase


git pull --rebase



but I am left wondering what branch is merged into the current branch. Shouldn't it be git pull --rebase <master> or git pull --rebase <dev>?


git pull --rebase <master>


git pull --rebase <dev>






Against upstream: stackoverflow.com/a/6244487/6309

– VonC
Sep 11 '18 at 4:54






I recommend keeping the two commands that git pull runs separate for a while, until you have them all straight in your head. Specifically, git pull runs git fetch first, then runs its second Git command. The second command can be rebase and if you run git rebase yourself, you'll see that it rebases the current branch against the current branch's upstream setting. The same default applies to git merge when you run it yourself. When you let git pull run that second command, things get more complicated.

– torek
Sep 11 '18 at 6:28


git pull


git pull


git fetch


rebase


git rebase


git merge


git pull






I recommend stackoverflow.com/a/30209750/6309: that way, a simple git pull will do the rebase automatically (after stashing the work in progress)

– VonC
Sep 11 '18 at 6:54



git pull




3 Answers
3



It first fetches origin/theBranch, then rebases your changes on top of origin/theBranch.


origin/theBranch


origin/theBranch



With a sketch :



before git pull --rebase :


git pull --rebase


*--*--*--*--A <- origin/theBranch

M--Y <- theBranch # your local branch



git pull --rebase step 1 : git fetch


git pull --rebase


git fetch


*--*--*--*--A--B--C--D <- origin/theBranch

M--Y <- theBranch



git pull --rebase step 2 : git rebase origin/theBranch


git pull --rebase


git rebase origin/theBranch


*--*--*--*--A--B--C--D <- origin/theBranch

M'--Y' <- theBranch






ah yes, so it rebases against the remote tracking branch

– MrCholo
Sep 11 '18 at 7:23






@LeGEC use M*, Y* in step 2 diagram.

– Rishabh Agarwal
Sep 11 '18 at 17:40







@rishabhagarwal you're right, done

– LeGEC
Sep 12 '18 at 6:18



It will pull the current branch in which you are working from remote and rebase it to your local branch.



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



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



Now,



git pull --rebase = git fetch + git rebase against tracking upstream
branch


git pull --rebase


git fetch


git rebase



Use Case: Suppose you and your team-mate are together working on a new feature on the same branch. He makes some changes and pushes them to remote. Now you need to fetch and rebase you branch to incorporate his changes.



You can also use git pull --rebase <currentBranch> in place of git pull --rebase.


git pull --rebase <currentBranch>


git pull --rebase



If you explicitly want to merge another branch changes to your local branch then you can use git pull --rebase <otherBranch>.


git pull --rebase <otherBranch>



When working with other people's repositories, there are a few basic Git commands to remember:


git clone
git fetch
git merge
git pull



These commands are very useful when interacting with a remote repository. clone and fetch download the remote code from a repository's remote URL to your local computer. merge is used to merge different people's work together with yours, and pull is a combination of fetch and merge.


clone


fetch


merge


pull



We will go in-depth on these commands below.



Clone



To grab a complete copy of another user's repository, use git clone like this:


git clone https://github.com/USERNAME/REPOSITORY.git



You can choose from several different URLs when cloning a repository. While logged in to GitHub, these URLs are available below the repository details:
Running `git pull --rebase`, what does it rebase against?



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)