2022-09-16
git-branch-tips

用 git 的好處,就是可以很方便的建立 & 刪除 branch
就記錄一下,目前有用到的 & 找到的使用 branch 的一些技巧 & 資料

使用 cmd 建立 local branch & 設定到 remote

  • 建立 local branch
    • git checkout -b <branch-name>
  • 將建立好的 branch push 到 remote
    • git push <remote-name> <branch-name>
      • <remote-name> is typically origin
  • 設定 push
    • git push --set-upstream <remote-name> <local-branch-name>
    • git push -u origin <local-branch-name>

清除 local branch 的方式 (單一的 branch)

  • 清 local branch 的方式
    • git branch -d <branch>

清除 remote branch 的方式 (一次 sync branch)

  • 跟 origin fetch 時,一併清除 remote 上不存在的 branch
    • $ git fetch --prune origin

清除 remote branch 的方式 (單一的 branch) - 不常用

  • 清 remote branch (已刪除的 branch)
    • $ git remote prune <remote>
    • `$ git remote -v

origin https://gitserver.com/user/repository.git (fetch)
origin https://gitserver.com/user/repository.git (fetch)
`

Reference

Read More