Everyday Git usage

Taking the chance to work in a team environment with different developers, I’ve faced many times a lack of documentation for everyday Git commands, which personally define mandatory to avoid mess.

To be clear, these occurring errors have been dictated by a change of OS which I usually work with, from Windows to Mac OS and so then from a Git UI usage to a command line usage. As you could imagine it’s quite hard at the beginning to keep track of modification, since the 2 methods are pretty different.


Consequentially to what above, one of the commands which I appreciated the most, it’s the amend one. It allows you to add files or edit the comment to your commits.

Add file without edit prompt to the last commit:
$ git add #namefile
$ git commit --amend --no-edit

Modifying the comment:
$ git commit --amend

Now there’s 2 way to push these modifications and are related to local commit only or to remote. If you have the commit locally, then you can simply push. Whenever you want to modify something already pushed to remote, then you will required to force it, since the branch do not match:

$ git push origin NAMEBRANCH --force

A very big not about this: pushing in this way you will override any modification made by anyone else, so unless you work alone, it’s preferred to be done while you work on your branch.



An analogue scenario for mistakes remedy is the reset command. I usually use this when I want to avoid multiple and useless commits, them merge them together. Another case can be if your hotfix cant be applied or your last commit has broken something and you prefer to reset all the modifications.

To remove the last commits and remove the modifications
$ git reset --hard head~1

To remove the last commits and keeping the modifications, usually for merge or fix them
$ git reset --soft head~1

As in the previous case, to way to push will change if the modification is local or remote.



If you have to handpick too many commits separately and all together or if someone interrupt your SCRUM session for a modification,  the command line could probably require too much time even after you become very proficient with Git.

A very handy node module I found to simplify the cases above, which will probably occurs very rarely, is Ungit (link), from which I stolen the xkcd strip above (if you do not get it.. link).

Technically talking, it’s a GUI for Git, which can be launched simply running a command inside your project. I usually prefer to run it in a second terminal due to log spam.


I hope you will found these suggestions clear and helpful just have been for me!



Related content:

WordPress permalink and redirect made simple

If you are using WordPress inside a company, will come the time to change the permalink structure of your custom posts type (CPT), as request by the SEO department. I said company, because almost nobody will invest so much money for such a thing. In my case, the request has been to create a structure … Continued

Editor friendly shortcode: wp.mce.views

One of the coolest features WordPress offers us is the shortcode. They give the possibility to render a complex design with a lot of properties and connect an interface to it to input the values. It also can render an actual template as preview of is final result. The UI can be powered with AJAX … Continued

Styleguide framework: kss

If you or your company is planning to recreate a framework, it’s mandatory to have a sort of inventory of all the components, with a word styleguide. This not only will help you to remember the markup, but will be necessary for your colleague to understand how to create elements and avoid repetition, which means … Continued

New theme from scratch (with free download)!

Even I still wonder where I found the time to code a new website, through I have no free time at all, I finally accomplished to develop a theme also for me from scratch, using the starter theme Sage (ver 9 cames with bootstrap and needs to be cleaned, duh). The whole to-do list planned … Continued