Skip to content

Instantly share code, notes, and snippets.

@ronsun
Last active July 21, 2022 06:37
Show Gist options
  • Save ronsun/647e2971b56bc57aa83ec714f1aa5f09 to your computer and use it in GitHub Desktop.
Save ronsun/647e2971b56bc57aa83ec714f1aa5f09 to your computer and use it in GitHub Desktop.
Git Commands

Delete local branches with no remote branch

git branch -vv | grep -v origin | awk '{print $1}' | xargs git branch -D

Delete multiple branches by pattern

reference

  • Check the branches match pattern
    git branch | grep "<pattern>"
  • Delete them
    git branch | grep "<pattern>" | xargs git branch -d

Referesh lists from remote branches

reference
git remote update origin --prune

Sync original from remote

reference
git fetch --prune

Sync unmerged pull request to my fork

git remote add JohnDao-Repo https://github.com/JohnDao/AwesomeProject.git  
git fetch JohnDao-Repo  
git merge JohnDao-Repo/issue-fix-branch-1

push an existing repository from the command line

Learn more

still need to create an empty repository on github manually.

-u is short for --set -upstream

echo "# TryDocFx" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/ronsun/TryDocFx.git
git push -u origin master

Remove the remote if added a incorrect remote

git remote rm origin
git remote rm origin git@github.com:username/myapp.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment