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