0

We are 2 developers who want to collaborate on some of our small projetcs, we are using Git in order to do this.

We are using a client called SourceTree which replaces the need of using commands for Git.

The question: What happens if we push our changes at the same time? We would like to avoid overwriting each others changes if possible.

Thank you for reading, and hopefully being able to answer my question.

VirtusB
  • 59
  • 10
  • In command-line git, unless you push with `--force` you can't overwrite changes on the remote repository. I don't use SourceTree, but I imagine it's the same. – Ajedi32 Nov 03 '16 at 13:15
  • 1
    Git is pretty good at handling conflicts, if you've both changed the same line of code, you'll have "merge conflicts" which must be resolved manually by you or your 2nd developer, without `--force` nothing will be overwritten automatically by Git. – naththedeveloper Nov 03 '16 at 13:18
  • there is an indepth explanation for this in another SO question, http://stackoverflow.com/questions/4643998/how-git-works-when-two-peers-push-changes-to-same-remote-simultaneously – root Nov 03 '16 at 14:59

1 Answers1

0

By default, you will not overwrite the other developer's code when pushing at the same time, unless you're using --force option.

As you're using SourceTree --force option is disabled by default. You can enable it by checking: General > Allow force push (not recommended for you)

Another thing to do to avoid this situation, is to always git pull before you git push.

Akram Fares
  • 1,653
  • 2
  • 17
  • 32