Useful git commands
This is a quick and dirty git cheat sheet of all the commands I frequently forget how to do with Git:
- See which remote is configured
- Stop tracking file permissions
- Debug Authentication Issues
- Find Unmerged Branches
- Export GitLog as a file
- Change commit message
- Empty commit message
Commit nothing
Sometimes you need to just commit something to trigger some CI/CD process. This is how you do that:
git commit --allow-empty -m "Trigger notification"
See the remote
I frequently mislabel project folders on my local and easily lose-track of the remote each directory points to. The solution, this short git config command that shows me the remote URL:
Another way you can do this is open the git config file in a text editor like Nano or VIM. The config file can be found within the .git
directory at the root of your project:
The output of which would look something like this (example taken from the Hugo static site generator documentation repository):
Stop git tracking file permissions (chmod)
Occasionally repositories bring with them their permissions that need to be updated on the remote. A nightmare when working with deploy keys as theyโre one way. So set the following config rule to false to stop git from tracking file permissions / chmod changes.
Debug ssh/git authentication
The following command runs an ssh test connection with the -T
flag that tests an SSH connection to a remote. In this case, it tests the current account has the correct credentials to access BitBucket.
Find branches that have/not been merged yet
Useful when removing โchecked outโ branches from your machine. The last argument is the branch you want to check against, in our example here it is develop.
Export the log as a file
Useful if you want to export a list of commits into a spreadsheet and do some analysis but personally only ever used this once.
Changing the output
You can expand this export feature by using the --pretty=format
argument:
Make a spreadsheet
Nothing too special here just exports the data fields in a TSV format so you can open them in the spreadsheet software of your choice.
Change the default editor
Change last commit message*
*On the last non-pushed commit.
This will directly edit the message.
Shortening this to the following opens the whole commit into an editor for updating.