kuniga.me > Docs > Git Cheatsheet
git checkout -- <file>
git reset --hard HEAD~1
NOTE: this doesn’t remove untracked files
git checkout .
git clean -fd
# (optional) first, see what files will be purged
git clean -n
# purge
git clean -fd
git stash -- <file>
git stash pop
Creates new branch foo
:
git branch foo
Changes to branch foo
:
git checkout foo
List existing branches:
git branch
Delete branch foo
(move away from it first):
git branch -d foo
Add new remote repo shorcut/alias. For example, I want public
to refer to the repository at git@github.com:kunigami/my-repo.git
.
git remote add public git@github.com:kunigami/my-repo.git
List remote repos associated to this local repo:
git remote -v
Send changes to a remote repo + branch, for example, the remote repository aliased as origin
, branch test
:
git push origin test
“Pull” remote branch (e.g. my_remote_branch
) that does not exist in your local repo and switch to it. Note: this only works if my_remote_branch
only appears in exactly one of the remote repos:
git switch my_remote_branch
Mark file as resolved:
git add <filemame>