Skip to content

Instantly share code, notes, and snippets.

@HarmJ0y
Created May 31, 2016 00:46
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save HarmJ0y/d2107e1834ebfada83f0c54d711eb2e6 to your computer and use it in GitHub Desktop.
Save HarmJ0y/d2107e1834ebfada83f0c54d711eb2e6 to your computer and use it in GitHub Desktop.
Common git commands
Show remote branches:
git branch -v -a
To check out the remote branch:
http://stackoverflow.com/questions/1783405/checkout-remote-git-branch
git fetch
git checkout <branch>
Create and checkout a local branch:
git checkout -b <NAME>
Push a local branch to remote:
git push origin <NAME>
Delete local branch
git branch -d <branch_name>
Undo last commit locally:
git reset --hard HEAD~1
To prevent having to type in your username every time:
in .git/config for the given project:
change url from this -> https://github.com/PowerShellMafia/PowerSploit/
to something like this -> url = https://harmj0y@github.com/PowerShellMafia/PowerSploit/
To pull PRs:
Add "fetch = +refs/pull/*/head:refs/remotes/origin/pr/*" under [remote "origin"]
in .git/config
To pull a PR change:
git checkout origin/pr/118
git pull
# unstage a file (so it’s not committed)
git reset HEAD <file>...
closing issues with tagging:
git commit -m "closes #104"
squashing unpunished commits-
http://stackoverflow.com/questions/6934752/combining-multiple-commits-before-pushing-in-git
squash other commits-
http://stackoverflow.com/questions/5189560/squash-my-last-x-commits-together-using-git
new messages:
git reset --soft HEAD~3 &&
git commit
preserving messages:
git reset --soft HEAD~3 &&
git commit --edit -m"$(git log --format=%B --reverse HEAD..HEAD@{1})"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment