Delete a Tag on Git

git tag -d [tag]
git push origin :[tag]

If your tag has the same name as one of your branches;

git tag -d [tag]
git push origin :refs/tags/[tag]

See all Branches

git branch

Create a Branch from previous commit

git branch branchname <sha1-of-commit>

Push the new Branch to server

git push origin BRANCH_NAME

Clone a specific Git branch

git clone -b <branch> <remote_repo>

Rename the master branch name

git branch -m old_branch new_branch # Rename the branch locally
git branch -m new_branch # Rename the currently checked out branch
git push origin new_branch
# Then go to GitHub UI settings/options, if the old branch was 'master', change 'Default Branch' to another branch that is not 'master'. Then
git push origin :old_branch # Delete the old branch

Revert uncommitted changes including files and folders

# Revert changes to modified files.
git reset --hard

# Remove all untracked files and directories. (`-f` is `force`, `-d` is `remove directories`)
git clean -fd

Remove a Commit That Is Already Pushed to Git

Firstly, find out the comit that you want to revert back to.

git log

For example, commit 7f6d03 was before the 2 wrongful commits. Force push that commit as the new master:

git push origin +7f6d03:master

The + is interpreted as forced push. You can also use git reset to undo things. Then force push.

git reset 7f6d03 --hard
git push origin -f

Reset local repository to be like the remote repo

Setting your branch to exactly match the remote branch can be done in two steps:

git fetch origin
git reset --hard origin/master

If you want to save your current branch’s state before doing this (just in case), you can do:

git commit -a -m "Saving my work, just in case"
git branch my-saved-work