Reputation: 1191
I am a GIT newbie so I have some basic questions about git commands, merging, etc. I just did some changes to code, I did a git commit, and then I tried to do the following command :
git push origin test:test
(What does this syntax mean? I know I'm using branches called test
)
There was an error since some else made changes before I did my push. So the the error said I need to do get the code changes and merge.
What command do I do to see what the differences are between my area and what's been changed by the other person? There is git diff but syntax should I use?
I want to merge my changes in with his changes. How do I do that?
Upvotes: 1
Views: 2460
Reputation: 1383
git push origin test:test
This pushes your changes to the local branch called test
to the remote branch called test
. The test:test
part is the (optional) <refspec>
option to git push
.
The <refspec>
format is <src>:<dst>
. The way you have used it you are pushing from local branch called test
to remote branch also called test
. A branch called test must exist on the remote called origin
.
For Question 1, you want to fetch the changes (but not merge them with your working files) and then diff, do;
git fetch origin test:test
git diff ..origin
Note I'm only including the refspec
option since you have used it in your push example - it may not be necessary - by default git fetch should look for a branch on origin with the name of your checked out branch... but I digress...
For Question 2, you want to merge branch origin (which after the fetch, is up-to-date with the remote origin) into your working copy;
git merge origin
+1 for Felix Fling's comment about pro git book...
Upvotes: 1
Reputation: 43690
To see the changes between what you have and what other people have done do:
git diff origin/test
In the case that you are in, you do not need to as your remote has been updated, but you will want to do git fetch
to make sure that your remote status is updated.
All you need to do is git pull
to get the updated changes.
I recommend also doing it like so git pull --rebase origin test:test
The --rebase
option will just add your commits after the changes that are on the origin. It will help keep the history cleaner otherwise you will see merge commits of your branch into itself. But that is up to you.
Upvotes: 1
Reputation: 8236
You need to git pull origin test:test
to get the changes made by the other developer and merge them into your working directory. After you resolve any conflicts and commit you will be able to push.
git push origin test:test
means you are copying the changes you have made in your local repository (clone) on branch test
(the left-hand test
) back to the original repository (origin) from which you made your clone on branch test
(the right-hand test
).
Strictly speaking, if the branch names in the local and origin are the same then it is sufficient to write git push origin test
.
Upvotes: 1