Deleting a Git branch locally and remotely

You may have accidentally created a local branch or a remote branch on your local machine or remote host, respectively. In other cases, you may simply want to delete the local or remote branch.

Delete the local branch

To delete a local Git branch, you need to specify the –delete or -d flag in your git branch command (the latter is just an alias for –delete).

$ git branch --delete local-branch

Or you can also use like this

$ git branch -d local-branch

As for force deleting , you can use like this

$ git branch -D my-local-branch-name

Delete a Remote Branch

You can delete a remote branch using as below.

$git push origin --delete remote-branch

Now, once the remote branch is removed from the remote host, you need to make sure that the other machines are also in sync. The branch has been removed from both the local machine and the remote host, but other machines may still have the old tracking branch. This can be listed by running git branch -a.

To ensure that all machines are in-sync, you need to run

$git fetch --all --prune

Yuuma



アプリ関連ニュース

お問い合わせはこちら

お問い合わせ・ご相談はお電話、またはお問い合わせフォームよりお受け付けいたしております。

tel. 06-6454-8833(平日 10:00~17:00)

お問い合わせフォーム