Reputation: 32721
I have to use different computers. I updated file A, B and other files in one and B, C and other files in another.
Updates in file B are different part of code. I have committed in both. I pushed A and B to the github.
Questions:
Now what should I do in another?
Should I just pull? Or should I push first?
If I push, will file A be overwritten?
If I pull, will file C be overwritten?
What kind of process do I need to take?
What do I need to do with file B which has different version? Can I merge them?
Upvotes: 1
Views: 171
Reputation: 133238
The usual scenario is that you do a pull before you push up your changes. But it might be the case that the current ancestor of your commits is the same since you pulled the last time (i.e. all the others haven't pushed anything yet), which means no merge is required and you can just push your changes without needing to pull.
Once someone else has pushed their changes in between, then you always have to pull their changes into yours (this is where git creates what is called a merge commit, which is a commit that hasn't been created the usual way with git add, git commit etc). Now your repository is synched with the latest changes and you can safely push to sync the central repository with yours.
In this case you have to pull first, which means that C will not be overwritten, since both repositories have the same version (remember, you only changed B on both repos).
In the case of B, where you have two divergent versions that must be merged by git, there might be conflicts. But this is exactly what a pull is, it's a fetch (to sync your repositories) and a merge between your local branch that is tracking the remote branch, e.g. master is merged with origin/master.
And finally the same thing will happen to A, the changes made in the first repo to A will be a trivial merge into A in the other repository, since the modified A is modified from the same version (identical blobs) of A in the other repo.
Hope this cleared some stuff up.
Cheers!
Upvotes: 0
Reputation: 944
You have to first pull, so that your additions are on top of what is in the server. Once you've pulled (which will merge the previously pushed mods with your local mods), then you can push. BTW: This is not github, this is plain git. I suggest the following book to understand git workings:
Upvotes: 2
Reputation: 54830
Pull -> rebase -> push: http://learn.github.com/p/rebasing.html
Upvotes: 1