I've used a number of various Git cheatsheets over the years, usually duing a moment of "how do I do __ again?" and sometimes during a moment of panic like "Shit! Undo that commit!"
Recently, I (finally) "removed my training wheels" and uninstalled the UI client I had for Git, for two reasons:
* Save for the occasional git clone action
The combination of features now more or less baked into VSCode (plus a few useful extensions) and my consistent terminal (WSL or Git bash) use marked the death knell for the UI tool. The only thing I miss from the tool is a visual identifier in my Repos folder. As I have a very small number of "parent" folders containing repo clones, it's helpful to be able to see if any of them contain uncommitted changes or the like. However, in the scheme of things, this is a pretty minor "nice to have" deal.
For Future Me's sake, below are the Git commands I most frequently use or for which I forget their syntax. I have not included links to documentation or explanations of the commands.
git clone https://github.com/username/reponame.git
gh-pages
)git checkout --orphan empty-branch
git rm -rf .
git commit --allow-empty -m "root commit"
git branch branchname
git checkout [-b] branchname
git branch -al
git remote add origin https://github.com/username/reponame.git
git remote -v
master
to main
(starting locally)git branch -m master main
git push -u origin main
git fetch --prune
Sometimes, depending on environments, I might have cloned something with HTTPS and need to change to SSH (for using key authentication, for example) or vice-versa:
git remote get-url origin
git remote set-url origin git@github.com:username/reponame.git
(change to SSH)git remote set-url origin https://github.com/username/reponame.git
(change to HTTPS)Undo last commit (ideally before push
):
git reset --soft HEAD~1
Normal commit
& push
:
git commit
git push
git status
git push
git pull
[--prune
]git fetch
[--prune
]git update-git-for-windows
This is my own personal short list and is far from complete. Most of these commands are now muscle-memory based, but having a reference to my commonly-used commands will hopefully make Future Me's life better.
Comments