Nit Improves Your Git Workflow.

{{{
Today I released “nit”:https://github.com/apotonick/nit, which is my attempt to provide a small and simple wrapper around git that helps me (and you!) save typing and optimizes git workflows. So I can focus on stuff that really matters.

h3. It’s All About Status!

I found it particularly annoying when I commit and add files with git since I usually copy+pasted the file names manually to git commit which involves keyboard _and_ mouse and so on and so on.

Here’s how nit does it.

$ nit

I just call the blank nit command in my working directory.

# On branch master
# Changes not staged for commit:
#   (use "git add ..." to update what will be..
#   (use "git checkout -- ..." to discard cha..
#
#   modified:   on_stage.rb  [a]
#   modified:   staged.rb  [b]
#
# Untracked files:
#   (use "git add ..." to include in what will..
#
#   brandnew.rb  [c]
#   new.rb  [d]

This is a shortcut to @git status@ with some additional information: The status screen renders a file index for each file which can be used on the command-line.

Indexes per default are characters on the right-hand side of the filename.

#   modified:   on_stage.rb  [a]

This “can be configured”:https://github.com/apotonick/nit#alternative-indexing, in case you prefer digits or want the index to prepend the filename.

h3. Commiting And Adding Files.

Now, having those file indexes you naturally don’t need to provide the entire file name anymore. Just give nit the indexes.

$ nit commit a c

This will interpolate the indexes and run

git add on_stage.rb
git add brandnew.rb
git commit

Note that *adding files is obsolete*. With nit, you just commit files and it will add them automatically.

The following will do the same, using nit’s auto-expansion and index splitting.

$ nit co ac

Actually, you can *use any git command* via nit, it will just do the index interpolation.

$ nit diff ac

h3. Ignoring Files.

Often I find myself having +10 files modified and the @git status@ screen gets confusing. This happens especially when refactoring bigger chunks of code.

Mostly, I work on, say, 3-4 files at a time and want to incrementally commit changes in this “file group” while the rest of the *modified or added files get in my way*.

# On branch master
# ..
#
#   modified:   on_stage.rb  [a]
#   modified:   staged.rb  [b]
#   modified:   lib/new.rb  [c]
#   modified:   TODO  [d]
#   modified:   CHANGES  [e]
#   modified:   lib/new/more.rb  [f]
#   modified:   lib/new/less.rb  [g]
#   modified:   test/new_test.rb  [h]

I could use @git stash@ to hide the changes I’ve made to the other files. After 20 minutes, *I will have forgotten the stash*, my changes, and I lose parts of my refactoring. Sucks.

Nit allows you to ignore files. They are simply no longer considered in the nit status screen.

$ nit ignore abdeh
$ nit

# On branch master
# ..
#
#   modified:   lib/new.rb  [a]
#   modified:   lib/new/more.rb  [b]
#   modified:   lib/new/less.rb  [c]
#
# Ignored files: 5

I found this really helpful as I really just see the files I am working on at that very moment. And – nit reminds me that there’s still other files invisible.

h3. Pushing And Pulling.

And, once I’m happy I just do

nit push

This will find out the current branch and push to origin.

git push origin master

Works for both @push@ and @pull@.

h3. Summary.

I am aware of the fact that git comes with many of those functions. I just don’t want to remember all the internals, how to configure git, how to change my shell prompt, aliasing git commands, how to use `git commit -p` and so on.

Nit simply reflects many steps of my personal everyday workflow. It really helps me typing less whilst allowing me to keep my hands to the keyboard and away from the mouse and my pants.

*No longer must I copy file names but use indexes!*

The character indexing makes it super easy to look at the screen while typing.

Ignoring files helps me focusing on my current task, which can be a 5 minute refactoring, without the pain of stashing-and-forgetting.

h3. From Here And On.

The next versions of nit will allow extending the tool with your own commands – either as gems or in a @.nit@ directory. Also, I have several other, breathtaking features planned.

If you want more, “just let me know”:https://github.com/apotonick/nit/issues.

And now, give it a go.

gem install nit

}}}

5 thoughts on “Nit Improves Your Git Workflow.

  1. Nit is ingenious, but I have one question, can I pass a commit message on the command line, without having to go into VIM or whatever text-editor git is set up to use?

    Like

  2. eremite: I avoid typing or copy/pasting file paths by using “git add -i”. Then files are presented as a numbered list and you can add tracked/untracked files just by typing their numbers (or ranges of numbers) e.g 1,4,5,7-10

    Like

  3. Why do you copy/paste the files in git commit manually? Could you give an example?
    Why git add is obsolete??

    Nevertheless nice tool!

    Like

Leave a reply to Filippos Cancel reply