Skip to content

Instantly share code, notes, and snippets.

@jl
Last active August 28, 2018 00:40
Show Gist options
  • Save jl/1218df8127e108d38a387c965248cb76 to your computer and use it in GitHub Desktop.
Save jl/1218df8127e108d38a387c965248cb76 to your computer and use it in GitHub Desktop.
git user interface productivity

gitk: visualize branches

gitk is useful for visualizing the history as a series of branching vertical lines, one commit per horizontal line:

# see history up to where I am
gitk

# see history on some other branch
gitk origin/master

# visualize history of where I am and multiple remote branches
gitk HEAD origin/master origin/release-62

# see everything
gitk --all

# find commits that added or removed a regex (also called "pickaxe" search)
gitk -Sfoo

# find commits with lines that changed containing regex
gitk -Gfoo

git gui: manage your next commit

Recall that git has a "staging area" which is where you propose the changes that will go into a commit (which doesn't necessarily have to align with your actual local file system changes). This staging area is also called the index in git documentation. staging == index

I find git gui extremely useful for visualizing and managing the index. I find it much faster and less error prone than git add <file> and git reset HEAD <file>, two commands I basically never type anymore.

The git gui has two areas on the left, unstaged and staged. Staged is the difference between the index and HEAD. This is exactly what will BECOME the next commit when you git commit. Unstaged is the difference between your filesystem and the index.

To view differences:

  • clicking on a filename in unstaged will show you what changes are in the local filesystem that you haven't staged
  • clicking on a filename in staged will show you what you are proposing to change in the next commit for that file

To accept changes:

  • Clicking on an icon in unstaged will move all changes for that file to staged. Since there are no unstaged differences left, the icon will disappear from unstaged.
  • Clicking on an icon in staged is the reverse: remove all staged changes for that file, moving it back to unstaged.
  • For more fine-grained control, you can right-click on the diff area on the right to stage / unstage chunks of code, or even individual lines! This allows you to just select some changes, even within the same file, for the next commit.

Note: I never use the Stage Changed, Sign Off, Commit, or Push buttons in git gui. I only use it to manage the index. I do commits, pulls, and pushes from the command line, because I want full control over what is happening there and don't want to accidentally do the wrong thing. Also, because of the way our git hooks and linters are set up, using the Commit button might make git gui appear to crash because it's waiting for (invisible) interactive console input from the user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment