ICE-5
1/16/2020 - 7:24 PM

git cheatsheet

Important note

  • git uses double score -- as flag marker.
  • Use standard push and pull to avoid mistake.

Command

Standard push & pull

  • push
git push <origin> <local-branch>:<remote-branch>
  • pull
git pull <origin> <remote-branch>

Remote

  • Add remote origin
git remote add <new> <remote-repo>
  • Change remote origin
git remote -v
git remote set-url <origin> <new-ssh/http>

Branch

  • Clone single branch
git clone --single-branch --branch <remote-branch> <remote-repo>
  • Create new remote branch
git push <origin> <local-branch>:<new-remote-branch>
  • Delete local branch
git branch -d <local-branch>
  • Delete remote branch
git branch -d <local-branch>
git push <origin> --delete <remote-branch>
  • Create a local branch to catch up with remote branch
git checkout --track -b <new-local-branch> <origin>/<remote-branch>
  • Prune remote branches to sync
git remote prune <origin>

Allow unrelated history

git pull <origin> <remote-branch> --allow-unrelated-histories