CP
cpxPratik/useful-git-commands
Some useful git commands that I have come across
useful-git-commands
Delete remote branch then delete local branch
git push origin --delete <branch_name>
git branch -d <branch_name>Clean-up old remote git branches. IOW, prune tracking branches not on the remote
git fetch origin --prune
git fetch origin --prune --dry-run # dry run the command
or
git remote prune originList git branches variations
git branch -r
git branch -a
git remote show origin
git ls-remote --heads originRemove cached tracking of files on git
git rm -r --cached .Checking out remote branch test in local
git fetch origin
git branch -v -a
git checkout -b test origin/testReset previous commit without staging into the working directory
git reset HEAD^Reset previous commit with staging
git reset --soft HEAD^Reset to origin/master with staging
git reset --soft origin/masterRemove git tracked file which is now gitignored
source: https://stackoverflow.com/a/19095988/2137210
git rm --cached . -r
git add .
git commit -am 'Remove ignored file'Merge branch with no common commits, IOW, with unrelated histories
source: https://stackoverflow.com/a/53663271/2137210
git pull origin <remote_branch_name> --allow-unrelated-historiesOn this page
Contributors
MIT License
Created January 23, 2019
Updated November 22, 2024