What happens when you git push and someone else has already done something you don’t have on the local repo?

Sorry, I'm pretty new to Git, and it's hard to find answers to such complex phrases (at least for me) on Google.

Say I'm calling Joe and I'm working on software with my colleague Bob.

We have Repo A upstream, and we have Repo A clones on our local machines, where we code, commit and periodically click on the same branch , say, the master. I know that this is not technically the best way to do this, but, for example, for the sake of.

Now, what happens if we both work on the same file. Bob local file that he has not yet clicked has contents

 // awesome program [some edits by Bob] 

My local file, which I have not clicked yet, has the contents

 // awesome program [some edits I made] 

Bob presses, after a second I press. What is happening now?

Will the file on the remote device be

 // awesome program [some edits I made] 

or

 // awesome program [some edits Bob made] 

or perhaps if there is a way to do this, I would like it to be

 // awesome program [some edits Bob made] [some edits I made] 

Sorry for the noobishness :(

+5
source share
3 answers

Git will refuse your click. It will tell you that new changes have appeared on the server and will force you to try before you can click. So you get

 // awesome program [some edits Bob made] [some edits I made] 

on your local computer. Then you can press it on the remote control.

+5
source

Firstly: you cannot normalize regular regular git push , because when you were on the local host your remote master changed. therefore git will offer you a forced press with the -f option. those. git push -f But it is not recommended to push the general branch unless you have good reasons, such as interactive rebasing !

Second: on this post, git tells you that something is happening with your remote repository, so you do git status , and yes, it says "Your branch and 'origin/master' have diverged, and have 1 and 1 different commit(s) each, respectively." . You must update your local repo; so you do git pull or in this situation the best team, git pull --rebase and amazing! git also refuses your attraction and says that you have conflicts in the example file. because you both and Bob are editing the same file and the same lines !

Finally: see the link and resolve the conflict. You can save your changes to either Bob or Both. then make changes and git push to update the remote repo. what is it!!!

+3
source

I am not 100% sure that this is what you want to do, but when you commit, a new revision must be created. Each new revision will replace the previous version. See if this info helps: Git Squash Chips

+1
source

All Articles