News for hackers. Stuff that matters.
Re:Distrusting git by jbellis on Saturday October 01, 2011 @01:24PM (#3060512)
Can you elaborate? A lot of beginner level material explains "pull" as a combination of "fetch" + "merge." What makes the latter saner?
Re:Distrusting git by click170 on Saturday October 01, 2011 @01:30PM (#3060528)
By doing a fetch first, and a merge in a separate operation, you're at least presenting yourself with an opportunity to check the code that you are merging.

With `git pull`, it is all done in one operation.

Of course, if you've already reviewed the code or are pulling from your own remote repository then `git pull` is likely fine.

Re:Distrusting git by gcv on Saturday October 01, 2011 @10:28PM (#3061827)
Agreed. After a fetch, I always review the changes on the remote branch. Depending on the circumstances, I can then make an informed decision about my own code, with the following possible outcomes:

1. I might choose not to merge. The upstream code may be bad, or it may not be ready for a merge. I may need to do some more work to prepare my own code to merge.

2. I might wish to perform a fast-forward merge (if one is possible).

3. I might wish to force a non-fast-forward merge (if a fast-forward is possible). This is often a good idea, as it helps keep groups of commits related to a particular feature isolated.

4. I might wish to rebase.

Re:Distrusting git by lucisferre on Monday October 03, 2011 @01:08PM (#3067134)
I treat pulls as a sync and always rebase local changes before pushing them. Merge pulls make for a very messy and verbose history.
Re:Distrusting git by nahname on Saturday October 01, 2011 @01:32PM (#3060535)
When calling fetch and then merge (or using rebase), you have more control over how the other changes impact your commits. Just pulling will result in a merge commit that contains all of the changes between the point you last pulled. This becomes confusing because it will look like you are adding files or making changes, when you are actually not.

The reason this happens is because git uses directed graphs and there is no link between the point at which you diverged from master and the other changes came in. The merge commit creates this. Unfortunately, it looks like you just committed everything that changed on both branches and the history can be difficult to track and/or confusing.

Fetch then merge will make the history more clear, but you still create a merge commit that will include all of the file changes (correct me if I am wrong here). git pull --rebase will take your changes out of the equation, pull in the new history and then replay them against the updated master branch. This is nice because your commit will only include (at this point) any merge conflicts resulting from your changes.

For a better explanation, with diagrams, see http://progit.org/book/ch3-6.html

Re:Distrusting git by meatmanek on Saturday October 01, 2011 @05:25PM (#3061144)
> Unfortunately, it looks like you just committed everything that changed on both branches and the history can be difficult to track and/or confusing.

I don't think this is really true. You'll just introduce a single merge commit on top of both your commits and the other person's. Yes, if you diff that merge against your own work, you'll see all the work that other people committed, but I think it's fairly well understood that a merge commit is just that - you merging your changes with other changes.

It can be a bit tricky to read the log when merge commits are involved, but try the --graph option or a graphical log tool.

Re:Distrusting git by alinajaf on Saturday October 01, 2011 @01:36PM (#3060549)
fetch is a fairly straightforward operation with predictable (i.e. get me all the objects and refs in the remote repo) but 'merge' actually moves the branch(es) in your local repo around.

After you do a fetch you can go on to do a merge just as though you did a git pull, but if you break down the steps then you now have the option to do a rebase or other operation as you see fit.

Re:Distrusting git by ori_b on Saturday October 01, 2011 @01:53PM (#3060591)
Do the fetch, diff against remote/branch and see what changed, look at the commit logs, and then merge.
Re:Distrusting git by bennoleslie on Saturday October 01, 2011 @08:24PM (#3061600)
Sure, I would agree with that, but in this case I already knew what the one commit I was pulling did. And the fetch,diff, merge wouldn't have helped. The file that was destroyed wasn't changed in the commit that was fetched.
Re:Distrusting git by mhartl on Sunday October 02, 2011 @02:04PM (#3063494)
Running

  git pull --rebase
is a good practice. That way you can abort and roll back if there are any serious conflicts.
Re:Distrusting git by hesselink on Sunday October 02, 2011 @04:10PM (#3063874)
Be careful with this though: if you have a merge ready to push, and you pull with rebase, your merge will be 'flattened' and all commits in it duplicated on your current branch. I've been bitten by this a couple of times.
Re:Distrusting git by gcv on Sunday October 02, 2011 @02:43PM (#3063591)
Only if you actually want to rebase! While rebasing is great, it rewrites history and should not be done lightly.
Re:Distrusting git by fphilipe on Saturday October 01, 2011 @01:28PM (#3060522)
It rewinds your work, fast forwards to the fetched branch and applies your work on top of it. It doesn't create a merge commit, which can pollute your tree unnecessarily.
Re:Distrusting git by davvid on Saturday October 01, 2011 @01:37PM (#3060553)
I believe you're describing "git rebase". e.g.

    git fetch
    git rebase origin/master
instead of:

    git pull
which you can also do with:

    git pull --rebase
But really, the preferred way is to use topic branches. So if you're on branch "foo", this is how you integrate into master.

    git checkout master # because it always matches upstream
    git pull            # this will always fast-forward
    git merge foo
    git push
That does create a merge commit but it does it in the right direction (master 1st parent, topic branch 2nd). You get to see the parallel development which is good to preserve in the history. Otherwise, rebasing is nice because it keeps the history linear.
Re:Distrusting git by fphilipe on Saturday October 01, 2011 @03:30PM (#3060882)
Yeah, you're right. I must have misread the question.

Didn't know about `git pull --rebase`. Thanks for that.