2015年11月23日 星期一

Git 操作常見問題集

Git 操作常見問題集
  • 我加入了遠端的 repo,想要更新他的 branch 清單

    git remote update <remote name> --prune

  • 我現在有一個本地 branch 我想要拉一個遠端的 branch 下來合併

    切換到要合併的 branch
    git checkout <local branch name>
    然後拉下來
    git pull <remote name> <remote branch name>
    然後你就會看到很多 conflict XDDDDDDDDD

  • 想把現在的 branch 推上去 remote

    git push <remote name> <local branch name>

  • 已經修改了某些檔案,突然想切換 branch(或者原本忘了切換)但又不想 commit

    這是發生在我身上的真實案例,我想開發一個新功能,結果忘了先把 branch 切到 new_feature_xxx,在 master 下就直接開始寫 code 了,這真的很慘。這時候就需要 stash !它可以將目前的修改暫存起來,讓目前的 git 是上一次 commit 的狀態。

    暫存當前狀態
    git stash
    切換到別的 branch
    git checkout <local branch name>
    把剛剛修改的東西較叫回來
    git stash pop

  • 替 branch 改名

    git branch -m <old name> <new name>

Reference:
How to update remote branch list on local machine?

Written with StackEdit.

沒有留言:

張貼留言