Reputation: 334
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.
Upvotes: 2
Views: 1199
Reputation: 1425
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.
Upvotes: 4
Reputation: 76892
Bill already covered that
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
Upvotes: 1