Skip to content

Instantly share code, notes, and snippets.

@zmiftah
Last active April 22, 2019 06:30
Show Gist options
  • Save zmiftah/2dd4100a1aedb7a9413d7fcd9a2ee329 to your computer and use it in GitHub Desktop.
Save zmiftah/2dd4100a1aedb7a9413d7fcd9a2ee329 to your computer and use it in GitHub Desktop.
Git Command History so that I won't forget
Q: How to add files
A: git add -A
Q: How to commit changes
A: git commit -am "Comment"
Q: How to see history of commits
A: git log --oneline --decorate
Q: How to undo `git add -A`
A: git reset --keep
Q: How to create and checkout a branch
A: git checkout -b branchName
Q: How to rename a branch
A: git branch -m branchName newBranchName
Q: How to merge a branch
A: git checkout master; git merge branchName
Q: How to push a branch
A: git push origin <branchName>
Q: How to remove a commit from remote
A: git push origin +HEAD^:master
Q: How to add remote repository
A: git remote add origin git@<webiste>:<username>/<repository>.git
git remote remove origin
git remove -v
Q: How to remove a commit on remote
A: git push <branch> +HEAD^:<branch>
Q: How to modify existing, unpushed commits?
A: git commit --amend
Q: How to undo commit
A: git reset HEAD~
Q: How to use stash
A: git stash
git stash list
git stash apply
git stash clear
Q: How to show diff commits by a file
A: gitk filename.ext
P: The remote end hung up unexpectedly while git cloning
S: git config --global http.postBuffer 524288000
Q: How to delete a file from git repo
A: git rm --cached <filename>
Q: How to delete a branch remotely
A: git push origin --delete <branch_name>
Q: How to delete a branch locally
A: git branch -d <branch_name>
git branch -D <branch_name>
@zmiftah
Copy link
Author

zmiftah commented Apr 22, 2019

TODO: rebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment