1

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.

  1. 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?

  2. I want to merge my changes in with his changes. How do I do that?

John Szakmeister
  • 44,691
  • 9
  • 89
  • 79
user565660
  • 1,171
  • 3
  • 20
  • 37
  • 5
    If you are just starting, I recommend to read the Pro Git book: http://git-scm.com/book. – Felix Kling Apr 19 '13 at 00:33
  • This may help you with various concepts: http://stackoverflow.com/questions/3329943/git-branch-fork-fetch-merge-rebase-and-clone-what-are-the-differences/9204499#9204499 – Michael Durrant Apr 19 '13 at 00:54

3 Answers3

1

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.

Peter Gluck
  • 8,168
  • 1
  • 38
  • 37
  • To resolve conflicts, you will want to do `git mergetool` this will walk though the files that are conflicting and allow you to resolve the conflict. https://www.kernel.org/pub/software/scm/git/docs/git-mergetool.html – Schleis Apr 19 '13 at 01:07
1

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.

Schleis
  • 41,516
  • 7
  • 68
  • 87
  • That `git diff` command will only work if you first update the remotes refs either via `git fetch` or `git remote update`. – John Szakmeister Apr 19 '13 at 00:51
  • correct, I neglected that as the OP had tried to pull and so a `fetch` had already occurred. Thanks for the addition. – Schleis Apr 19 '13 at 01:05
1

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...

mounds
  • 1,303
  • 12
  • 11