Reputation: 4081
Me and my friend are working with some little project and we have problems with Git. We have one main repository which is created by me. My friend forked it and cloned it to his local machine.
Now when I make some changes I push commits to my repository by doing:
git add -u
git commit -m "message"
git push origin master
I'm getting changes from repository by git pull
command.
My friend is commiting changes by executing commands:
git add -u
git commit -m "message"
git push origin master
and he is getting changes from repo by git pull upstream master
command.
After we do it we have problem with synchronizing our repositories. When my friend creates Pull Request it says there are conflicts... and it happens each time we push commits.
How to make it work that if my friend do some changes and create Pull Request, git will automatically add his lines of code without any conflicts to my repo?
Upvotes: 3
Views: 124
Reputation: 44659
Well, if you change the same line of code, obviously you'll have conflicts - that's normal and that's what you want to happen. You wouldn't merge code you haven't tested.
So, before doing a Pull Request, any person sending it should pull
(basically: pull
= fetch
+ merge
) the lastest changes from your repository, resolve conflicts and make sure its version is up to date.
Then, if you push new commits to your repository before accepting the PR, the PR will be out of date and can't be automatically merged. So, you can either pull your friends branch on your own workplace and resolve the conflicts - or you have your friends pull
your master branch again and etc.
When working closely with someone though, I always prefer to give writing permission to my colleague; so he can push as he want.
The only thing really important to understand here is that before merging any branch on another, the branch must be up to date (pull
and conflicts resolved).
Upvotes: 3