Search code examples
gitgithubgit-pushgit-pullgit-stash

Git pulling and pushing when working in a team


I've started working on a project with another developer and have only just realised how limited my GIT knowledge is. Here's the deal:

  • I've been making changes during this week, and want to push them to master
  • My colleague made changes to the same project yesterday and pushed them last night

How am I supposed to proceed?

If I try and push my changes, I'll get error because my code is out-of-date.

So, I'm told I should STASH my changes, then PULL his changes into my working directory, then STASH APPLY my changes back.

But when I do that, I get conflict errors because we have BOTH changed the project file.

If I then look in the files to see the conflicts, I find that they're not "labelled" like a normal conflict, so I can't fix the problem! I can't even compare my two versions, because the conflicted versions are the old ones.

Any help, very much appreciated.


Solution

    1. If you have tracked files that are changed, either add & commit them or stash them
    2. git fetch the changes from the remote branch
    3. git rebase your commits on top of the commit history established in the remote branch you just fetched
      • You may need to resolve conflicts here. Git will tell you, if so. You can typically use the default "mergetool" to produce save a file resolving the conflict.
    4. git push your history which now contains your latest series of commits. Your friend can follow this same procedure to get your commits into his local history as well.

    Reading the official documentation is always important. Also, I've found this visual cheatsheet to be helpful as well.