I have a git branch I need to nuke all traces of. I think I need something like
git filter-branch --index-filter 'git -D <branch>' --tag-name-filter cat -- --all
or maybe
git filter-branch --index-filter 'git rm --cached *' --tag-name-filter cat -- <branch>
Then I would
git push -f origin :<branch>
I'm hesitant to try them without knowing for sure what they'll do or if they'll work.
Simply do git push origin --delete to delete your remote branch only, add the name of the branch at the end and this will delete and push it to remote at the same time... Also, git branch -D , which simply delete the local branch only!...
In Git, local and remote branches are separate objects. Deleting a local branch doesn't remove the remote branch.
Like all deletes in svn, the branch is never really deleted, it's just removed from the current tree.
That means you no longer need to keep and use that branch, so it is a common best practice to delete it so it doesn't clutter up your code. Local branches are branches on your local machine and do not affect any remote branches. The command to delete a local branch in Git is: git branch is the command to delete a branch locally.
The command to delete a remote branch is: Instead of using the git branch command that you use for local branches, you can delete a remote branche with the git push command. Then you specify the name of the remote, which in most cases is origin.
Here we will check out our main branch from my test branch. Now in order to delete the test branch locally, we use the command : We will delete my test branch as an example. Note: The -d option will delete the branch only if it has already been pushed and merged with the remote branch.
To list out all the local branches, you use the following command: I have two, branches, master and test2. I am currently on the test2 branch as the (*) shows: I want to delete the test2 branch, butit is not possible to delete a branch you are currently in and viewing. If you try to do so, you'll get an error that will look something like this:
Let's say you want to nuke evilbranch
.
You say you want to delete all of a branch's history. This technically includes the initial commit, which is probably more commits then you want. So first, identify which commit you consider to be the first commit of that branch. Let's say it's 666bad
. Now we need to find all references to it. Run
git branch -a --contains 666bad
git tag --contains 666bad
Now delete them all. You can either use git commands, or just go into .git/refs
.
Do this on every computer that might have the file.
Make sure you are not in detached head.
Now we can kill all the commits, and therefore all the code, that is no longer referenceable (from this gitHub link):
git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin
git reflog expire --expire=now --all
git gc --prune=now
Again, this should be done on each computer.
Finally, use this on each computer.
Note: 666bad
is the first commit after evilbranch
split from wherever it came from, i.e., the first commit that is only evilbranch
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With