-
-
Save vvit/c5787c422c5b26e309d5 to your computer and use it in GitHub Desktop.
Frequently used commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//If git keeps asking the passkey: add it to the keychain | |
ssh-add -K ~/.ssh/id_rsa | |
//create and switch to a new branch | |
git checkout -b <branch> | |
//push new branch to a repo | |
git push -u origin <branch> | |
//merge 'dev' into 'master', always enter a message during merge: | |
git checkout master; git merge --no-ff dev; git push; | |
//delete a branch (locally and then remotely) | |
git branch -d <branch> | |
git push origin --delete <branch> | |
//rename the current local branch (to do it on the server one should re-create a branch) | |
git branch -m <newname> | |
//add a remote | |
git remote add <name> <url> | |
//unstage a file | |
git reset HEAD <filename> | |
//undo last commit loosing all the changes locally | |
git reset --hard HEAD~1 | |
//undo all local commits loosing all the changes aka get back to origin's state | |
git reset --hard origin/develop | |
//...leaving local files and index | |
git reset --soft HEAD~1 | |
//edit last commit message or add files. To add new files: stage them before calling this command. | |
git commit --amend | |
//delete a file from the repo only (keep it locally) | |
git rm --cached <filename> | |
//discard local changes after the latest commit | |
//...for unstaged file: | |
git checkout -- <filename> | |
//...for all unstaged files: | |
git checkout -- . | |
//...for all staged files: | |
git reset -- . | |
//stash / show stashes / pop | |
git stash / git stash list / git stash pop | |
//apply a stash / delete stash | |
git stash apply < stash@{1} > / git stash drop < stash@{1} > | |
//show a stash | |
git stash show -p < stash@{0} > | |
//create new branch from stash | |
git stash branch <branch> | |
//how your teammate can pull the new branch: | |
git fetch origin | |
git checkout --track origin/<branch> | |
//if your teammate deleted a branch - remove it locally | |
git fetch -p | |
//create and share an annotated tag | |
git tag -a v1.2 -m 'The new version' | |
git push origin --tags | |
//delete a tag locally | |
git tag -d <tagname> | |
//and in a repo | |
git push --delete origin <tagname> | |
//diff between unstaged files and last commit (HEAD) | |
git diff | |
//diff between staged files and last commit (HEAD) | |
git diff --cached | |
//list files permissions | |
git ls-tree HEAD | git ls-files -s | |
//visualize | |
git log --graph --decorate [--oneline] | |
//show commit patch | |
git log -p -1 <commit> | |
//rebase interactively last 2 commits | |
git rebase -i HEAD~2 | |
//interactive staging | |
git add -p filename | |
y to stage that hunk | |
n to not stage that hunk | |
e to manually edit the hunk (useful when git can't split it automatically) | |
s to split piece into smaller hunks | |
? help | |
//interactive staging | |
git add -i | |
//This will create three separate revert commits | |
git revert a867b4af 25eee4ca 0766c053 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment