F21
F21

Reputation: 33401

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

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?

Upvotes: 5

Views: 124

Answers (2)

4u.Ans
4u.Ans

Reputation: 1279

Another option to clear (on your local) deleted branches on the server could be

git fetch –p

Hope this helps.

Upvotes: 0

VonC
VonC

Reputation: 1326676

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]

Upvotes: 1

Related Questions