2

I see a lot of examples of:

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>?

  • Against upstream: https://stackoverflow.com/a/6244487/6309 – VonC Sep 11 '18 at 04: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 06:28
  • I recommend https://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 06:54

3 Answers3

3

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


With a sketch :

  • before git pull --rebase :

    *--*--*--*--A <- origin/theBranch
                 \
                  M--Y <- theBranch   # your local branch
    
  • git pull --rebase step 1 : git fetch

    *--*--*--*--A--B--C--D <- origin/theBranch
                 \
                  M--Y <- theBranch
    
  • git pull --rebase step 2 : git rebase origin/theBranch

    *--*--*--*--A--B--C--D <- origin/theBranch
                          \
                           M'--Y' <- theBranch
    
LeGEC
  • 46,477
  • 5
  • 57
  • 104
0

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

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.

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

Rishabh Agarwal
  • 1,988
  • 1
  • 16
  • 33
-3

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.

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

Clones a repository to your computer

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?

hellow
  • 12,430
  • 7
  • 56
  • 79