Reputation: 7279
Here, we are migrating our source code to github, and this transaction is giving me headaches :)
what I did: I gone to our workspace (is an eclipse project), and did git init
and git add .
and then git commit -am "first commit"
everything worked fine, and then, i just pushed it to github. success too.
but there is a big problem: My friend just made a change on a file named A.java
and I just changed B.java
. ok, not a big deal. then, he pushed it to github. whei I try to push, my push is rejected. Ok, I did a git pull github master
and then, push again, and now, my 'commit message' turns like Merge branch 'master' of github.com:germantech/projectName
Ok, what am I doing wrong?
ps: sorry about my english
Upvotes: 1
Views: 384
Reputation: 8488
are you in the same repo or on different repos? If you are you need to rebase your changes and push again
git pull --rebase github master
git push github master
Upvotes: 1
Reputation: 468081
You're not doing anything wrong - when you do git pull github master
, git goes to the repository indicated by the remote github
, fetches everything needed for the master
branch, and then merges it into your current branch. Before the pull, you had the following history:
O --- A (master)
... where O
is the commit with the message "firts commit" and A
is the commit that introduced your changes to A.java
. Your friend, meanwhile, has the history:
O --- B (master)
... and that has been pushed to GitHub. When your git pull github master
merges that into your history, it creates a "merge commit" to represent the state of the tree with the changes from both master
branches:
O --- B --- M (master)
\ /
---A ---
If, instead, you wanted to keep the history linear, you could do git pull --rebase github master
, which would instead would "replay" your commits that aren't in the remote version of the branch on top of that remove version of the branch:
o --- B --- A' (master)
Some people prefer that - I personally don't care.
Upvotes: 3