Git can do a lot of things, but I’m lazy remembering all the commands I need – some of them are like 5 words long. So I’ll put this here so next time I don’t have to search for them.
Update list of remote branches:
git remote update origin --prune
Or set automatic pruning globally:
git config --global fetch.prune true
Delete local and remote branch:
git push origin --delete <branch_name> git branch -d <branch_name>
Push all branches to remote:
git push --all -u
Push this new branch to remote:
git push origin branchB:branchB
Add annotated tag:
git tag -a v1.4 -m "my version 1.4"
And push tags to remote
git push --follow-tags
To kill all the local changes do
git reset --hard HEAD
To reset to a state of a commit
git reset --hard SHA
To make sure all the extra files are removed do
git clean -f -d
Move local commits into different branch.
Quite often I start hacking and coding while being on
master branch and then I commit and then I try to push, but then I get git policies kicking in saying I can only do a Pull Request and push to master. So I need to move committs to a different branch. Here is the way:
1) Create new branch with your changes.
git checkout -b mybranch
2) Push new branch code on remote server.
git push origin mybranch
3) Checkout back to master branch.
git checkout master
4) Reset master branch code with remote server and remove local commit.
git reset --hard origin/master
Stolen from this answer