Skip to content

Instantly share code, notes, and snippets.

@dr563105
Last active March 2, 2022 09:02
Show Gist options
  • Save dr563105/5f1cd9c636f2b26204914e323b4f4bb1 to your computer and use it in GitHub Desktop.
Save dr563105/5f1cd9c636f2b26204914e323b4f4bb1 to your computer and use it in GitHub Desktop.
Git commands
git config -l # for local config
git config --global -l # for global config
git config --global user.name "name"
git config --global user.email "email address"
git config --global credential.helper cache # store login credentials
git add remote https://repo_here # add new remote repo
git remote -v # list of remote repo
git remote show origin # more info on origin
git add .
git add file
git branch <branch> # create a new branch
git checkout <branch> # checkout to the branch
git checkout -b <branch> # create and switch to the branch
git branch -d <branch> # delete branch locally
git push origin --delete <branch> # delete remote branch
git merge <branch> # merge branch with current branch
git merge --abort # merge start over 
git commit -m ""
git commit --amend -m "message" # amend previous commit
git commit -a -m "message" # add and commit together
git push origin
git pull origin
git pull --rebase  # to rebase local head with remote head
git fetch
git push --set-upstream origin branch / git push -u origin branch # change upstream to branch
git clone link
git status
git log 
git log -p # commit's history including all files and their changes
git log --graph --oneline # limits commit message to one line
git log --graph --oneline --decorate # same as previous
git log --graph --oneline --all # for all branches
git show commit-id # shows a specific commit
git diff
git diff file
git diff --staged # staged files
git reset [file] # go back to previously known working state
git rm [file] # remove file working directory and staging area
git stash # Put current changes in your working directory into stash for later use.
git stash save "msg" # prev with a msg
git stash pop # bring the most recent stash to the working directory and delete from stash history
git stash pop stash@{<number>} # bring numbered entry to the wd and delete from stash history
git stash apply stash@{<number>} # just like prev but doesn't delete from stash history
git stash drop stash@{<>} # delete the entry from stash history # pop = apply+drop

revert a remote commit

https://gist.github.com/gunjanpatel/18f9e4d1eb609597c50c2118e416e6a6

References

https://www.csd.uoc.gr/~hy255/refcards/git-refcard.pdf

https://www.freecodecamp.org/news/git-cheat-sheet/

https://about.gitlab.com/images/press/git-cheat-sheet.pdf

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