Deleting a remote branch2:06 with Jay McGavren
Deleting local branches doesn't delete the remote branches they track. In this video, we'll show you how to delete remote branches.
- Let's suppose we decided we no longer need the
- We can delete it with
git branch -d:
git branch -d more-letters.
- But even that only gets rid of the local branch. If we run
git branch -a, we'll see that there's still a remote
- We shouldn't leave a bunch of unused branches on our remote repo. Let's delete the remote branch, too.
- The only way Git is set up to make changes to remote repositories is through the
- So to delete a branch on a remote repository, you need to add the
- You type
git push, the remote repository name, the
--deleteoption, and the name of the branch you want to delete:
git push origin --delete more-letters
- You should see a message that the remote
more-lettersbranch has been deleted.
$ git push origin --delete more-letters To /Users/jay/th/decoder - [deleted] more-letters
"Refusing to update checked out branch" errors
If you're trying to delete a remote branch that points to a repo that's in a different directory on your local computer, you may see an error like this:
$ git push origin --delete more-letters remote: error: refusing to update checked out branch: refs/heads/more-letters remote: error: By default, updating the current branch in a non-bare repository remote: is denied, because it will make the index and work tree inconsistent remote: with what you pushed, and will require 'git reset --hard' to match remote: the work tree to HEAD. remote: remote: You can set the 'receive.denyCurrentBranch' configuration variable remote: to 'ignore' or 'warn' in the remote repository to allow pushing into remote: its current branch; however, this is not recommended unless you remote: arranged to update its work tree to match what you pushed in some remote: other way. remote: remote: To squelch this message and still keep the default behaviour, set remote: 'receive.denyCurrentBranch' configuration variable to 'refuse'. To /Users/jay/th/decoder ! [remote rejected] more-letters (branch is currently checked out) error: failed to push some refs to '/Users/jay/th/decoder'
If this happens, do the following:
- Change to the directory for the repo you're using as a remote:
- Switch to a different branch, so that the branch you're trying to delete isn't checked out:
git checkout master
Now you should be able to change back to your other repo and delete the remote branch successfully.
Note that you won't have this issue with remote repos on hosting services like GitHub, because no branches will be checked out there.
You need to sign up for Treehouse in order to download course files.Sign up