Search code examples
gitbitbucketgit-mergegit-pushgit-fetch

Afraid git commit and push will accidentally overwrite changes


I am working on a project with a friend using a remote git tool bitbucket.org. So far that we have been working on the master branch at different times, and then commit and push those changes to the remote site for the other to use.

Now he has committed and pushed his changes out to the repository while I was working on my own, and I am afraid that if I push out my commit it will re-write his commit completely. Are my fears correct? I think I should create a new branch, fetch his changes into the master branch, and then merge the two, and then push. Is this a good strategy? Or I am worrying for nothing. A little advice would be great.


Solution

  • The whole idea of VCS is that you won't corrupt data by doing this. You can attempt to push, if your code is out of sync you will be told you have to accept the upstream changes before you can commit.

    Once you have accepted the changes and merged them you can apply your code to the HEAD.