I’m a complete newbie to Git, not really sure what’s going on. My buddy and I are working on a project together.
I fetched all the files from a remote server git fetch, so I now have a whole bunch of files.
-
I edit some of them, he edits some of them, etc.
-
I keep doing fetch everyday, and he begins to tell me that he has modified some of the files and updated them, but these changes do not show up on my end.
-
I open up Git GUI in Windows, on the left side there are two panels.
One says
Unstaged Changes– I’m taking this to mean these are
things I changed which will not be updated to a local repository
unless Iaddthem.The other one says
Staged Changes (Will Commit). Inside this
window, when I click on some of the files, I do see the updates my
friends have made which are NOT showing up in the files I’m editing,
and I think I also see changes I’ve made. -
I add all the files with
git add .in my directory -
I press the
commitbutton in Git GUI, now there are no more files in any of the two side panels, noUnstaged Changesand noStaged Changes (Will Commit). -
I check all the files and it seems like the changes from both my end and my friend’s end have been merged into one file.
I’m still not 100% sure what happened.
-
Question 1: Did I do this right?
-
Question 2: What exactly does
mergedo?
Because I keep merging with git merge origin/master and merging doesn’t seem to do a damn thing. I thought commit just writes a record down of your current version into some hash codes, but seems like commit is actually doing what I thought merge does – it’s merging changes.
Sorry for the long-winded question, just very confused.
I believe you’re misunderstanding
git fetch.It only fetches the changes made to a remote repository, in your case the
masterbranch in theoriginrepo, but it does not apply them to your tree (it only stores them locally in the.gitdirectory).git merge, on the other hand, applies the remote changes onto your repository.You have to use
git pull origin masterto pull your friend’s changes and merge them into your working tree. Essentially, agit pullis the same asgit fetchfollowed bygit merge.Check this out: Git Fetch vs Pull
ALTERNATIVELY
Your friend/you are not
pushing to the origin repository. Is your friend doinggit push origin masterafter he commits? Commits are local, and to “share” them with the rest of the world, you mustgit push.The only exception is when he is working directly on the
originrepository. Then he does not need to push as all his commits are already onoriginin his branch.