When you delete a branch on a remote repository (like GitHub or GitLab), the deletion does not automatically reflect on your local repository. This means that you might still see the deleted branch in your local repository. Here are the steps to ensure your local repository is up-to-date with the remote changes:
Fetch Remote Changes: Fetch the updates from the remote repository. This will update the local tracking branches with the state of the remote branches.
git fetch -p
The
-p
or--prune
option will remove any tracking branches that no longer exist on the remote repository.Delete the Local Branch (if it exists locally): If the branch also exists locally and you want to delete it, you need to remove it manually.
git branch -d branch-name
If the branch has not been merged, you might need to force delete it using:
git branch -D branch-name
Check for Stale Branch References: If you still see the deleted branches, they might be stale references. You can prune them with the following command:
git remote prune origin
This command will clean up the references to branches that no longer exist on the remote.
By performing these steps, you can ensure that your local repository is in sync with the remote repository and does not show branches that have been deleted remotely.
Thank you for reading until the end! If you have any questions or feedback, feel free to leave a comment. If you found it helpful too, give back and show your support by clicking heart or like, share this article as a conversation starter and join my newsletter so that we can continue learning together and you won’t miss any future posts.