- CheatSheet
- Clone new repository
- Abort all changes on current branch
- Cherry pick changes without auto commit
- Create new branch with checkout
- Delete local branch
- Uncommit last N commits (keep changes)
- Merge master to develop afeter commit to master only
- Resolve Conflicts on pull request
- Update feature branch with the latest commits of develop branch
- Stash changes created on "wrong" feature branch and apply them on the "right" one
- Undo uncommited changes
- Move uncommited changes to another branch
- Re-push develop branch after accidental deletion via PR develop into masters
clones repo into newly created subfolder
git clone <url>
git reset --hard HEAD
git reset --hard origin/<branch name>
git cherry-pick <commit id> -n
git checkout -b <branch name>
git branch -d <branch name>
Uncommit one last commit
git reset --soft HEAD~1
Uncommit two last commits
git reset --soft HEAD~2
Uncommit N last commits
git reset --soft HEAD~<number of commits to uncommit>
Get the latest version of master
git checkout master
git pull
Get the latest version of develop
git checkout develop
git pull
Merge master into develop
git merge master
Push the merge
git push
Swtich to the branch that I'm merging to some other branch
git checkout <source branch>
Pull for the target branch that I'm merging into
git pull origin <target branch>
- open solution in the VSCode
- go to the conflict files
- resolve (accept current or incoming or show differences and make changes manualy)
After resolving conflicts
git commit -m "Resolve merge conflicts"
git push
Go to the feature branch
git fetch origin develop:develop
Merge changes into the feature branch
git merge develop
On the "wrong" branch
git stash
Go to the "right" branch
git stash pop <index of the last stash>
Show list of all stashes
git stash list
This will unstage all files you might have staged with git add
git reset
This will revert all local uncommitted changes (should be executed in repo root)
git checkout .
You can also revert uncommitted changes only to particular file or directory
git checkout <some_dir|file.txt>
Yet another way to revert all uncommitted changes (longer to type, but works from any subdirectory)
git reset --hard HEAD
This will remove all local untracked files, so only git tracked files remain
git clean -fdx
WARNING: -x will also remove all ignored files, including ones specified by .gitignore! You may want to use -n for preview of files to be deleted.
To sum it up: executing commands below is basically equivalent to fresh git clone from original source (but it does not re-download anything, so is much faster)
git reset
git checkout .
git clean -fdx
git stash
git checkout <correct-branch>
git stash pop
Note: No need to use stash command. Uncommitted changes do not belong to any branch so just use
git checkout -b <new-branch>
find last merge commit e.g. 53172fe2fa71ace8d6f2a1442cba026da9c9345f
git fetch
git checkout 53172fe2fa71ace8d6f2a1442cba026da9c9345f
git checkout -b develop
git push