Skip to content

cpxPratik/useful-git-commands

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 

Repository files navigation

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 origin

List git branches variations

git branch -r
git branch -a
git remote show origin
git ls-remote --heads origin

Remove 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/test

Reset 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/master

Remove 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-histories

About

Some useful git commands that I have come across

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published