This guide will provide the procedure to remove the tracking branches that no longer exist on the Git remote repository.
How to Remove Tracking Branches no Longer on Remote Repository?
To remove tracking branches no longer on the remote, first, move to the particular Git repository. Then, clone the Git remote repository and the new remote URL. Next, fetch the updated remote repository and check the remote branches list. Go to the GitHub hosting service and check the existing branches list. Lastly, execute the “$ git remote prune origin” command to remove the tracking branch reference.
Step 1: Navigate to Git Local Repository
Move to the Git particular repository using the following command:
Step 2: Clone Remote Repository
Run the “git clone” command and clone the remote repository to the local repository:
Step 3: Add Remote URL
Next, add the remote URL using the “git remote add” command alone with the remote name and remote repository path:
Here, the “origin” is the remote name:
Step 4: Verify Remote URL
Then, verify the added remote repository URL with the help of the “git remote” command with the “-v” option:
Execution of the above command will list all the remote connections:
Step 5: Fetch Updated Remote Repository
Now, run the “git fetch” command to fetch the updated remote repository:
Step 6: List Fetch Remote Branches
To view all remote branches, run the “git branch” command with the “-r” option:
According to the below-listed output, the cloned remote repository contains four branches:
Step 7: Check Remote Branches
According to the drop-down branches menu, the remote repository does not contain the “dev” branch, which was fetched earlier on the local repository:
Step 8: Remove Reference
Run the “git remote prune” command with the remote name to remove the deleted remote branch reference:
It can be observed that the removed tracking branch is pruned successfully:
Step 9: Verify Removed Tracking Branch
Lastly, check the list of the fetch remote repository to verify the removed tracking branch:
Below output shows that the required remote branch reference is deleted successfully:
That’s it! We have provided the procedure to remove the tracked branches that are no longer on the remote repository.
To remove tracking branches no longer on the remote, first, navigate to the particular Git local repository. After that, clone the remote repository into the local repository and add the new remote URL. Next, fetch the updated remote repository and view the remote branches list. Open up the GitHub hosting service and check the existing branches list. Lastly, execute the “$ git remote prune origin” command to remove the tracking branch reference. In this guide, we have explained the method of removing tracking branches that no longer exist on the remote repository.