This page looks best with JavaScript enabled

Git 協作&分支相關

 · 

branch

show local branches

git branch

show remote branches

git branch -r

create branch

git branch xxx

switch branch

git checkout cat

switch and create new branch

git checkout -b sister

beanch rename

git branch -m cat tiger


複製 remote beanch 同名到 local 並 switch

git switch branch_name or git switch -t origin/branch_name
or
git checkout branch_name or git checkout -t origin/branch_name


delete branch

delete local branch

git branch -d dog
若刪除時還沒合併會報錯

delete remote branch

git push -d origin branch_name
or
git push origin :branch_name

強制刪除

git branch -D dog

預設 beanch

$(git symbolic-ref refs/remotes/origin/HEAD |cut -d/ -f4)

刪除所有 local branch,但排除 預設的 beanch

git branch |grep -v $(git symbolic-ref refs/remotes/origin/HEAD |cut -d/ -f4) |xargs git branch -d

刪除所有 remote branch,但排除 預設的 beanch

REMOTE_NAME=$(git remote)
git branch -r |grep "${REMOTE_NAME}/" |grep -v "$(git symbolic-ref refs/remotes/origin/HEAD |cut -d/ -f4)$" |grep -v HEAD |cut -d/ -f2 |xargs git push -d ${REMOTE_NAME}

沒權限的訊息

remote: Repository not found.
fatal: repository 'https://github.com/xx/test/' not found

delete last commit

git reset --hard HEAD~1 and do push forcly


remote

git remote -v
git remote set-url origin https://github.com/XXX/XXX.git


push

local branch l1 push 到 remote branch r1

git push origin l1:r1

建立關聯

git push -u origin l1:r1


stash

git stash
git stash pop
git stash list

git stash drop stash@{index}
git stash clear


commit

修改已經 commit 的 commit message

git commit --amend 進入修改