ronsun
11/15/2019 - 4:13 AM

git commands for specific targets

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