[Git] Xóa branch (nhánh) local và remote (server)

If you want to delete a branch, first checkout to the branch other than the branch to be deleted.

Ví dụ: Nhánh bạn cần xóa là developer_old

(Nếu bạn muốn xóa một nhánh, đầu tiên cần checkout sang nhánh khác nhánh cần xóa)

Tổng quát

git checkout other_than_branch_to_be_deleted

Cụ thể:

git checkout master

Deleting the local branch: (Cú pháp xóa nhánh ở local: (máy mình đang code))

Tổng quát (xóa nhánh ở local):

git branch -D branch_to_be_deleted

Cụ thể:

git branch -D developer_old

Deleting the remote branch: (Cú pháp xóa nhánh ở server, nơi mình sẽ remote lên để xóa)

Tổng quát (xóa nhánh ở server)

git push origin --delete branch_to_be_deleted

Cụ thể:

git push origin --delete developer_old

Xóa tất các nhánh ở local: (Thêm)

git branch | grep -v "master" | xargs git branch -D

 

Note: The -d option is an alias for --delete, which only deletes the branch if it has already been fully merged in its upstream branch. You could also use -D, which is an alias for --delete --force, which deletes the branch “irrespective of its merged status.” [Source: man git-branch]

-d là viết ngắn gọn của –delete và nó chỉ xóa khi nhánh đó đã được merged vào từ nhánh gốc nó base ra. -D là –delete và –force => xóa hết ko cần quan tâm

Ref: http://stackoverflow.com/questions/2003505/how-to-delete-a-git-branch-both-locally-and-remotely

Một suy nghĩ 3 thoughts on “[Git] Xóa branch (nhánh) local và remote (server)

Bình luận về bài viết này

Trang web này sử dụng Akismet để lọc thư rác. Tìm hiểu cách xử lý bình luận của bạn.