Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If we delete a branch on the server, can we automatically delete it in our local copy?

Tags:

git

branch

github

Usually, when I send Pull Requests on github, I would create a branch, make my changes, then ask them to merge that branch into their repo.

Once that is done, on Github, I delete the branch (but github just hides it). I then permanently delete the branch on the Github site.

Now that the remote branch is gone, how I can synchronize my local repo with the remote? I have tried fetching and pulling, but that does not delete the branches in my local repo.

Will I have to manually delete them from my repo, or is there some way to sync it?

like image 870
F21 Avatar asked Nov 12 '22 06:11

F21


1 Answers

You can try a:

git remote prune origin

(assuming the remote 'origin' references your GitHub repo)

This is explained in "cleaning up old remote git branches" (git branch -d localbranch)

I don't know of a native git command which would do both.
Only a script like "git_remote_branch" would delete a branch both on GitHub and locally

delete (aliases: destroy, kill, remove, rm)

Delete the remote branch then delete the local branch.
The local branch is not deleted if there are pending changes.

$ grb delete branch_name [origin_server]
like image 121
VonC Avatar answered Nov 15 '22 04:11

VonC