I have the following situation. I have worked on some files and didn't commit/push. My teammate has worked on some other files (different from mine) and already committed/pushed his changes. How can I safely pull his changes, and then commit and push mine? Thank you in advance.
-
Update from master, then commit. – mxmissile Mar 13 '19 at 15:46
-
Just do it. this is what GIT is designed to do. – Liam Mar 13 '19 at 15:47
-
1Possible duplicate of [When do I need to do "git pull", before or after "git add, git commit"?](https://stackoverflow.com/questions/18529206/when-do-i-need-to-do-git-pull-before-or-after-git-add-git-commit) – Liam Mar 13 '19 at 15:48
2 Answers
There are several different ways you could handle this. You could commit
your changes and then pull
. You could stash
your changes, pull
, and then apply your stash
. You could fetch
first, then commit
and rebase
. I personally like doing this a little more explicitly (with a fetch
followed by rebase
, instead of a pull
which combines a fetch
with a merge
), but that is just personal preference.
git fetch
git add <files to add>
git commit -m <commit message>
git rebase <branch to replay commit onto (i.e. origin/master)>
The rebase
step will provide you the opportunity to resolve any conflicts, if the other developer and you were working in the same space.
You should then be able to push
your changes.

- 1,407
- 10
- 18
Pulling and merging
- commit your changes
- pull the other changes
- fix merge conflicts if there are any
- commit
Stashing
- stash your changes
- pull the commits from the repo
- get back the stash code
Rebasing
Bill already covered that
branching
Create a branch where you commit your changes, switch back to the branch you were at and pull: Move existing, uncommitted work to a new branch in Git

- 64,414
- 37
- 100
- 175