Git config

Lots of us use git in a daily basis, myself included. We can say a lot of git, but I would not say that it is intuitive, or that it has nice shortcuts. Similar to what happens with VIM, over the course of some years and some jobs I collected a small list of git configurations that I find very comfortable to work with.

Damn! I failed again, no posts on summer 😀

Graphical git or command line git?

There’s a lot of nice graphical GUI for git. But this post is entirely related to command line git.

.gitconfig and aliases

Lots of people have opened the .gitconfig file, or have edited it indirectly. And it probably looks like this:

[user]
	name = kxtells
	email = my.email@gmail.com

But in this file, you can define aliases. An alias is nothing special, when given a command input git will try to expand it from its aliases file. For example, if we define the alias:
bar = commit

when writing git bar in the command line, git will expand it to git commit.

Basic pleasentries

Here your basic friends. Writing commit is too cumbersome? simply write ci

    ci = commit
    co = checkout
    br = branch
    fp = format-patch

Pushing

This one is quite simple, but I was so tired of writing the full command. It’s very common to work on a branch and want to upload that branch to the remote origin. pcb (push current branch) has a nice ring to it.

    pcb   = git push origin HEAD
    push-current-branch = git push origin HEAD

Logging

And here, the bane of our existance. The default log printing isn’t very sexy. It might be useful for quick views, but following a long log is not pleasant. Find here three nice logging options:

  • lg Log with one line and colors (for the current branch)
  • lgg Same as the previous one. But it also prints the branches found along the log.
  • lgb My precious. Print the full log (all branches)
    lg  = log --format=format:'%C(bold blue)%h%C(reset)  %C(bold green)%an%C(reset) %s'
    lgg = log --format=format:'%C(bold blue)%h%C(reset) %C(bold yellow)%d%C(reset) %C(bold green)%an%C(reset) %s'
    lgb = log --graph --all --format=format:'%C(bold blue)%h%C(reset) %C(bold yellow)%d%C(reset) - %C(bold green)%ar%C(reset) %C(white)%s%C(reset) %C(bold white) -- %an%C(reset) ' --abbrev-commit --date=relative

Then we have file logging, print the changes made to a file:

    fl  = log -u

Resetting changes

Not so common in my normal flow (since I check and re-check before changes are made), but useful nonetheless

    r1 = reset HEAD^
    r2 = reset HEAD^^
    r1h = reset HEAD^ --hard
    r2h = reset HEAD^^ --hard

Git SVN check commit list

When working with git-svn theres the dreaded moment of committing to SVN. I use this alias to know what will be committed before proceeding:

    lgc   = log --name-status git-svn..HEAD

The full list


    ci = commit
    co = checkout
    br = branch
    fp = format-patch


    pcb   = git push origin HEAD
    push-current-branch = git push origin HEAD

    lg  = log --format=format:'%C(bold blue)%h%C(reset)  %C(bold green)%an%C(reset) %s'
    lgg = log --format=format:'%C(bold blue)%h%C(reset) %C(bold yellow)%d%C(reset) %C(bold green)%an%C(reset) %s'
    lgb = log --graph --all --format=format:'%C(bold blue)%h%C(reset) %C(bold yellow)%d%C(reset) - %C(bold green)%ar%C(reset) %C(white)%s%C(reset) %C(bold white) -- %an%C(reset) ' --abbrev-commit --date=relative


    fl  = log -u
    r1 = reset HEAD^
    r2 = reset HEAD^^
    r1h = reset HEAD^ --hard
    r2h = reset HEAD^^ --hard

    lgc   = log --name-status git-svn..HEAD

That’s all folks

Well. That’s it. A subset of my .gitconfig that might be useful in most cases, not too specific and not too complicated. 😀

Advertisement

1 Comment

Filed under curious, tools

One response to “Git config

  1. Pingback: The dropped posts, and 2017 closing | Castells

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.