First this is different because this is for all branches not one. (All the ones I have found only specify this for a single branch at a time)
I work on a repo that has about 20-30 branches (long story bad practice I know I know)
anyways I was deleting some old commits using the git bfg cleaner and after using it you need to either delete and reclone the code or reset every branch.
I know how to set branches using
git fetch origin
git reset --hard origin/master
But is there a way to reset every branch with one command or do I have to do it one branch at a time?
I have a lot of local files ignored that I do not want to deal with copying and rewriting. (like IDE files, computer config files, etc...)
Just wrote a small tool that does this.
Advantages of this tool:
Here's the script:
You can use the following oneliner (based on that other answer):
git branch --format='%(refname:short)' | xargs -i sh -c "git checkout {} && git reset --hard origin/{}"
--format='%(refname:short)'
removes the annoying*
fromgit branch
-i
allow to use{}
as a placeholder for the branchWARNING: I didn't use that command a lot so it may not be entirely safe, see that answer if you want to make it safer.
You can use a script which which will loop over your branches and then do what ever you want on each one:
Is there a better ans simple solution?
Yes, simply clone the project again and you will have the same content as your origin.
This is exactly what you do manually per branch.
Note:
You can fetch all the data at once using this command:
Why not just delete all local branches, and then whenever a remote branch gets re-checked-out, you'll be synced?
xargs runs the provided command against every line of stdin, in this case "git branch -D" against every line of the original "git branch" command.
The "git branch -D" command will fail for current branch, but every other branch will get wiped.
Alternatively you could cook something up with "xargs" that runs "git branch -f" to force-set every local branch to its remote copy, but I think the "git branch -D" approach above is the simplest, and also the most straight-forward as far as consequences, potential hazards are concerned.