I’ve been using Git for some time now, both locally on my devices and with remote repositories such as GitHub. My blog posts have detailed some of my Git knowledge, and I thought I had quite good Git abilities, so what commands were missing from my skillset?
Note: I still find Git a funny name, here in the UK its a slang term for an annoying person. Creating a title for this blog post saw several edits with titles such as “Get Lit with Git” (I’m not young enough to use the term “lit” so hoping it does mean excellent), and “F*cked it with Git” (As in, screwed up using Git, I don’t swear on the blog so scrapped that one). However, I have gone with the more honest title referencing that I really could have used these Git commands earlier.
So with all that in mind, and to paraphrase Scorpion (Mortal Kombat), “Git over here!”.

Git Commands
Git Blame
Looking to throw some blame?
git blame FILENAME
Git blame will show who changed each line in a file. Just remember, although it is called blame its more about tracking down an issue rather than attributing blame.
Git Log (Focused)
Git log can show a lot of history, it can be easier when looking for the commits that change a particular file consider using the filename:
git log FILENAME
Instead of returning the full history this will return the commits where FILENAME was altered.
Git Commit –amend
Imagine you’ve just created the best piece of code ever, you save and stage the work, then git commit with a quick message to briefly summarise why the commit is needed. But wait, you’ve listed something wrong in the commit message or made or spelling mistake. Crud. Now your amazing code is overshadowed by a poor commit message.
Hey, none of us are perfect but hang on there is a Git command that can help.
git commit --amend -m "amended commit message"
git commit –amend takes the last commit and amends its message to a new message.
Git Commit –allow-empty
You might want to test an automated workflow that runs when commits take place, it can be a bit tedious creating a new file or adjusting some content just to create a commit to test the workflow.
git commit --allow-empty -m "Testing with empty commit"
The –allow-empty flag allows for an empty commit (no files changes).
Warning: The last two commands adjust commit messages and allow empty commits, nothing too destructive. The next two commands can be destructive, so be careful when using them.
Git Reset
Made a git commit that should not have been made? Or several git commits that should not exist? Git reset can help by resetting the commits.
git reset HEAD~
This resets the HEAD by 1 commit.
git reset HEAD~2
This resets the HEAD by 2 commits.
For example, if I created a file called “file66”, then added it with git add, and committed it with git commit -m “added filed66”, then it would show in my git log. Running git reset HEAD~ would then reset the commit and “file66” would show as a changed file that has not yet been committed.
Git Rebase
I’m going to write this again, incase you have skipped the warning above, Warning: This command can cause loss of commits (i.e. be destructive). A heads up as well, when using Git rebase interactively it loads my systems default terminal text editor (Vi), which has a slight learning curve (i for insert mode, :wq for writing and quitting etc).
git rebase -i HEAD~2
This command interactively (-i or –interactive) rebases the last two commits from the HEAD. The rebase shows the last X (2 in this example) number of commits and then gives options such as:
- pick (use the commit),
- reword (change the commits commit message),
- drop (remove the commit),
- squash (squash commits together)
Edit the command (e.g. change the word “pick” to “reword”) and then save the file for the interactive rebase to provide the options for the command (“e.g. if “pick” has been changed to “reword”, then saved, the rebase will then ask what the rewording should be).
If you have entered an interactive rebase and do not want to make a change then emptying the file and exiting should result in an “error: nothing to do” message (e.g. no changes to make).
