🔱 Git Commands You Didn't Know
September 23, 2020
5 min read
One of my favorite things about Git is being as simple as it is and also being customisable and one of those features is aliases. Git supports aliases which means you can give your commands any name you want. I prefer to set aliases for really long commands to avoid searching for them everytime I need it.
alias config in Git works like this.
From the example above, I won't need
git commit again.
git save will work good enough.
Add quotes around commands with multiple options.
git commit --amend allows you to change the last commit message.
recommit is simpler and much easier to remmember.
Commit amend with
--no-edit flag allows you to commit the new changes in repo with the last commit made, so you don't have to repeat the commit messages again.
git grep allows you to search in the repository for a keyword and it returns the various matches. It is cool, but I don't know what
grep means, please tell me if you do. I prefer
search instead, easy to remmember and easy to use.
Usually when I initialize a new repo, I'll stage all the files and I'll commit with an initial commit message.
git here does it all in one step. Just run it in the folder you want to make a new repo and you are good to go.
git blame is used to examine the contents of a file line by line and see when each line was last modified and who the author of the modifications was. If there was a bug, in a line, you find who
who did it and blame them.
archive commands allows you to create tarballs and zips of your whole repo or some.
git zip will make it easy to remmember. Just add the branch name.
git checkout with the
--orphan flag allows you to create a branch without any history from the parent branch. No commit, fresh out of the box branch.
git clone with
--single-branch --branch flags allows you to clone a specific branch from a repo and I can say, I've googled it more than 10 times. Aliasing it is better.
There is nothing wrong with
git log except that it is a little ugly, no color differences and if you want to customize it, you'll have to do some amount of googling. Fortunately, we have aliasing. Alias the command and you'll get a very pretty log of everything.
The series of commands that
fresh replace is used to create a new repository out of the contents of a subfolder.
filter-branch with it many flags take a the contents of a specified subfolder and replaces the content in the while repo with the content of the subfolder.
Add this to your