User Tools

Site Tools



Oh-My-Zsh git command alias reference (kudos to thoughtworks)

Things NOT to do

  • NEVER force push to remote branches

Reset file

git checkout -- path/to/file


git pull --rebase

# or

git pull --no-ff



git branch -a

Delete local

git branch -d test

Delete remote

git push origin --delete test

Cleanup branches on local which have been deleted on remote

git fetch --prune

How to: Fixup bad commit

git reset --soft HEAD^

# or

git reset --soft HEAD~1

Then reset the unwanted files to leave them out from the commit:

git reset HEAD path/to/unwanted_file

# or

git rm --cached path/to/unwanted_file

Now commit again, you can even re-use the same commit message:

git commit -c ORIG_HEAD

How to: Remove modified files from PR

git checkout origin/master -- src/main/java/
git commit -m "Removed a modified file from pull request"
git push origin <pull-request-branch>

How to: Rebase active branch onto another branch

First, commit your current changes

git commit
git checkout -b backup

Secondly, switch to the target branch

git checkout master

Thirdly, rebase the source branch onto the target branch

git rebase <parent commit hash BEFORE first feature commit> --onto <feature branch name> --committer-date-is-author-date

fatal: cannot rebase with locally recorded submodule modifications

"fatal: cannot rebase with locally recorded submodule modifications"

Run commands separately:

git fetch
git rebase
git submodule update
git_commands.txt · Last modified: 2022/11/15 05:35 by superuser

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki