Created
August 24, 2022 21:49
-
-
Save valterlobo/7edfb26ba19c0d3f07483c7ef27cb9b4 to your computer and use it in GitHub Desktop.
git 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
Pull from remote overwriting local changes. | |
i) git stash (revert and stash changes locally) | |
ii) git pull (pull from remote normally) | |
to retrieve changes, do | |
'git stash apply' | |
Delete only untracked files from working tree | |
git clean -f -d | |
Unstage files from index (but keep the files locally) | |
git rm --cached | |
Undo a merge | |
i) git checkout branch-name | |
ii) git log --oneline | |
iii) git revert -m commit-id | |
remove a file from remote | |
i) git rm filename (remove file from git) | |
ii) git commit -m "commit message" | |
iii) git push | |
Undo last n commits | |
git reset --soft HEAD^n (where n is the number of last commits you want to undo) | |
See diff between branches | |
git diff branch_1..branch_2 | |
Remove a tag from branch | |
i) git push origin :refs/tags/tagname | |
ii) git tag -d | |
Rename a branch locally & remote | |
i) git checkout old-branch | |
ii) git branch -m new-name | |
iii) git push origin :old-name new-name | |
Move existing, uncommitted work to a new branch | |
git switch -c <new-branch> (git 2.3 onwards) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment