If I am working on my branch, branch1
and then I push some commits while my team member was also working on branch1
--when it comes time for my team member to push his changes, he's now behind.
What is the easiest way for him to get my most recent commits, and attempt to merge his changes with mine? Let's assume he has already committed his changes before realizing this error.
I thought you'd do:
git pull origin/branch1 && git merge origin/branch1
but that doesn't seem to work at all.
I believe you'd do a rebase
, but I'm unsure of the process; all anyone talks about is doing rebase
with master
--but I don't want to do anything with master
at this point.
git pull origin/branch1 && git merge origin/branch1
git pull
git pull
is actually an alias to those 2 commands: git fetch + git merge
so your second part of the command is useless.
The way to grab changes is this - Several option:
# Update your local repo with the latest code:
git fetch --all --prune
# Merge the changes (you already did a pull)
git merge origin branch1
OR:
# grab & merge the latest changes into your current branch
git pull origin branch1
rebase
If you want your changes to be on top of the other changes then you can use the --rebase
flag when pulling the content.
# As before - update your local repo with the latest code:
git fetch --all --prune
# Merge the changes with the rebase flag
git pull --rebase origin/branch1
Image src: http://blogs.atlassian.com/
Stash + rebase automatically
You have those config which you can set:
rebase.autoStash
+ pull.rebase
rebase.autoStash
When set to true, automatically create a temporary stash before the operation begins, and apply it after the operation ends.
This means that you can run rebase
on a dirty worktree
.
However, use with care: the final stash application after a successful rebase
might result in non-trivial conflicts. Defaults to false.
pull.rebase
When true, rebase branches on top of the fetched branch, instead of merging the default branch from the default remote when "git pull" is run.
git config pull.rebase true
git config rebase.autoStash true