DEV Community

Discussion on: What is your favourite Git command?

Collapse
 
exadra37 profile image
Paulo Renato

Not really a git command per se, but once I use the OhMyZSH shell, that have lots of useful alias to git commands, I love the alias gwip and gunwip.

GWIP

$ alias | grep gwip -
gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign -m "--wip-- [skip ci]"'

This alias allows me to quickly commit everything, tracked and not tracked changes.

How to use

The current state of my branch is:

$ git status
On branch shipfast-on-docker_approov2-kotlin-wip
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   README.md

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    test.dev.to

no changes added to commit (use "git add" and/or "git commit -a")

Using gwip:

$ gwip
[shipfast-on-docker_approov2-kotlin-wip c7a96dd] --wip-- [skip ci]
 2 files changed, 1 insertion(+), 1 deletion(-)
 create mode 100644 test.dev.to

That results in this git log:

commit c7a96ddbcca0e4ef6d0f9085cd8d420610eccaa7 (HEAD -> shipfast-on-docker_approov2-kotlin-wip)
Author: Paulo Silva <paulos@criticalblue.com>
Date:   Mon Oct 7 15:25:41 2019 +0100

    --wip-- [skip ci]

 README.md   | 2 +-
 test.dev.to | 0
 2 files changed, 1 insertion(+), 1 deletion(-)

So the message --wip-- [skip ci] tells to the CI pipeline to not run for this commit, and at same time the --wip-- part will be used by the alias gunwip to undo what we have done with the gwip.

GUNWIP

$ alias | grep gunwip -                                                                                                                                                                                   
gunwip='git log -n 1 | grep -q -c "\-\-wip\-\-" && git reset HEAD~1'

The gunwip alias will undo any commit where the message contains --wip--, thus will undo what we have done with gwip.

$ gunwip
Unstaged changes after reset:
M   README.md

Leaving us with:

$ git status
On branch shipfast-on-docker_approov2-kotlin-wip
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   README.md

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    test.dev.to

no changes added to commit (use "git add" and/or "git commit -a")

Summary

During my day I use a lot this 2 commands in order to keep progressing in the code until I am finished with what I am doing, thus be able to proper commit the code.

I also push this wip commits upstream to be protected of an hard disk failure. I do this several times a day, and in the end of the day.