A guide to git in GNOME for the simple minded

I’m not too fond of terminals. This guide is for new GNOME contributors like me whose brain capacity for terminal commands is only so-so big. I will introduce you to 8 git commands worth remembering. I assume only vague familiarity with git: pulling, pushing and committing.

In GNOME you need to

  • keep your commits clean.
  • let your commits go through GNOME’s bugzilla as a patch.
  • make modifications to your commits based on feedback.

To do this, first, start doing your work in local branches. A branch is like doing a Save-As of your current git project including history and everything. The branch is independent and you can freely jump back and forth between “master” and your own branch.

Create a branch:
git branch yourname/yourbranch

Open a branch:
git checkout yourname/yourbranch

Delete a branch:
git branch -D yourname/yourbranch

Okay. Now, you have done your work and you need to file a bug on bugzilla. Commit your work with a max 80 character commit message and then make a *.patch you can upload.

git format-patch HEAD^
(creates a patch from your latest commit.)

Soon you receive an e-mail saying someone reviewed your patch, and they tell you to make some changes. So you make the changes and now you want to put them into your existing commit. You do this by first doing git add , and then do:

git commit --amend
(modifies your commit to include your changes.)

You can then create a patch from your commit again and upload your new work to bugzilla. Remember to mark the old patch as obsolete in there.

Let’s say you need to test someone else’s patch then. To do this you can do a:

git am mypatch.patch
(applies a patch to the top of your branch.)

This will apply a patch named mypatch.patch to your git folder. If you want to revert back to how it was before, then you can do:

git reset --hard HEAD^
(reverts the top commit of your branch.)

This will revert the latest commit so be careful. Work on a copy branch so you safely can mess around. There’s no easy ctrl+z here. You can run this reset command several times to go several commits back in time. You can keep track of where you are with:

git log
(shows the 5 latest commits on your branch.)

..and that’s it. I think this is everything you need to know to start contributing small patches to your favorite FOSS project. You can revert, copy, create and modify patches. Never be afraid of filing bugs, especially when you attach a patch to them. :)

8 thoughts on “A guide to git in GNOME for the simple minded”

  1. To be specific, this:

    git format-patch HEAD^

    with git-bz should be:

    git bz attach HEAD

    And:

    git am mypatch.patch

    should be:

    git bz apply

    Also:

    “This will remove the latest commit so be careful. ”

    is not strictly true. git never actually *removes* any commit unless you manually force a garbage collect of your local repository. All it does is it changes your branch to point to the previous commit and remove all changes from the checked out code. The old commit is still there somewhere in the “.git” subdirectory, and if you know the old commit id you can rever back to it with:

    git reset –hard

    If you don’t know the old commit id, chances is that you can find it somewhere in the output of:

    git reflog

      1. Just wanted to mention git reflog as a possibility to get back commits accidentally lost with git reset –hard or amended commits.

        When you have some time, check out git’s ingenious interactive rebase.

        Greetings from Hamburg,

        Lasse

  2. a tiny correction:
    A branch is like doing a Save-As of your entire git tree.
    not just the current folder

    [WORDPRESS HASHCASH] The poster sent us ‘0 which is not a hashcash value.

Comments are closed.

Leave a Reply

Your email address will not be published. Required fields are marked *