Skip to content

Instantly share code, notes, and snippets.

@dantheman213
Last active June 20, 2019 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dantheman213/afeeab3e223cc6595f2f to your computer and use it in GitHub Desktop.
Save dantheman213/afeeab3e223cc6595f2f to your computer and use it in GitHub Desktop.
Git Cheatsheet

Git Cheatsheet

This cheatsheet is to assist anyone new with Git with becoming familiar with common scenarious.

Commands

Reset single file back to last checkout

git checkout HEAD -- my-file.txt

Reset all added files back to last checkout

git reset HEAD -- .

Reset local git repo to last commited (includes local commits) check-in####

git reset --hard # Reset to code base

Go back to specific commit

git revert <commit>

Force git repo back to a different commit (undo bad commits)

git push -f origin <commit_id>:<branch_name>
git reset --hard <commit_id>
git pull origin <branch_name>

Reset local commit and sync repository to authoritative server version

git reset --hard
git clean -f -d -x
git pull

Move working files in a directory in current branch to another existing branch

git add <file(s)>
git stash
git checkout <branch>
git stash pop
git add --all .

Delete remote branch

git push origin --delete [branch]

Delete Local branch

git branch --delete [branch] [branch2] ...

Get all branches from server

git fetch

Sync branches with server (delete local branches that don't exist on server)

git fetch --prune

Push all local branches to remote

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