Git commands

35 || 1  || 2018-09-21 01:31:07 || root || || Bash

Useful Git commands:

  • Remove all local Git branches that don't exist in remote repository
  • Remove all local Git tags that don't exist in remote repository
  • Remove tag from remote repository
  • Remove tag from local repository
  • Create new Git branch and push it to remote repository
  • Checkout to the branch from remote repository

# Remove all local Git branches that don't exist in remote repository
git fetch -p && for branch in `git branch -vv | grep ': gone]' | awk '{print $1}'`; do git branch -D $branch; done

# Remove all local Git tags that don't exist in remote repository
git fetch --prune origin +refs/tags/*:refs/tags/*

# Remove tag from remote repository
git push --delete origin v1.1.0-tag1

# Remove tag from local repository
git tag --delete v1.1.0-tag1

# Create new Git branch and push it to remote repository
git checkout -b v1.1.0-feature1
git push origin v1.1.0-feature1
git branch --set-upstream-to=origin/v1.1.0-feature1 v1.1.0-feature1

# Checkout to the branch from remote repository
git checkout -b v1.1.0-feature1 origin/v1.1.0-feature1