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
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"
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:
git config --get remote.origin.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):
[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true precomposeunicode = true [remote "origin"] url = https://github.com/gohugoio/hugoDocs.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master
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.
git config core.fileMode false
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.
ssh -T email@example.com
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.
git branch --no-merged develop
Useful if you want to export a list of commits into a spreadsheet and do some analysis but personally only ever used this once.
# Local Dates: git log --date=local > commits.txt
You can expand this export feature by using the
# ISO Dates: git log --date=iso --pretty=format:"%h%x09%an%x09%ad%x09%s" > commits.iso.tsv.txt
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.
git log --date=iso --pretty=format:'"%h","%an","%ad","%s"' > commits.excel.tsv.txt
# Another date form git log --pretty=format:%h,%an,%ad,%s > commits.txt
git config --global core.editor "nano"
This will directly edit the message.
git commit --amend -m "New commit message"
Shortening this to the following opens the whole commit into an editor for updating.
git commit --amend