Reputation: 21
I'm new to Git and the problem I had today at my uni project is the following:
I didn't realize that he was coding at the same time as me -- he says that if he pulls my commit then his changes to the same files would be lost.
What do we do now, do I just tell him to copy those files to another place in his drive and then "combine" the changes? How do we avoid this situation in the future?
Sorry for the poor wording and stuff, as I said I'm a beginner and very clueless about this topic.
Upvotes: 1
Views: 534
Reputation: 140553
I didn't realize that he was coding at the same time as me
Welcome to the real world of programming. This happens all the time.
It is such a common problem that any decent version control system has built-in capabilities to merge changes automatically. Git is extremely powerful about that, when the changes are in different parts of a file, the second person doing a pull (or fetch/rebase) won't even notice. You only notice when git is unable to merge itself, then you end up with merge conflicts, which require human attention.
What do we do now,
Let's assume your coworker did a git pull
that fails because you pushed changes affecting some of this files. Each file will now contain the information about conflicting updates. Decent editors like Visual Studio code will show you all these conflicts, and allow you to pick this or that version of the corresponding code. Turn to this, and read the section about "Merge conflicts".
In other words, the real answer is: it is time for all of the people working with you to pick up a good book about git (like this one) and start learning about the tool you are using. You see, git is an extremely powerful, and sometimes confusing tool. If you are serious about learning programming, then you have to be serious about learning such tools as well.
Upvotes: 1
Reputation: 755
You and your teammate can have different branch using same repository.
git checkout master
git checkout -b 'yourBranch' #this branch for you
git checkout master
git checkout -b 'aliceBranch' #this branch for your friend
# when your done, push to related branch
git push origin <branchName>
Upvotes: 0