Languages
[Edit]
EN

Git - clean up git branches in my local repository (git remove all local branches except master)

9 points
Created by:
OneCricketer
460

1. Problem

Edit

How to clean up git branches in my local repository?
I am interested in cleaning up local repo, this are my requirements after cleanup:
- remove all local branches except master
- get all remote branches (refresh local list of remote branches)

Current state on remote repo:

Before in local repo:

After in local repo (same state as on remote repo):

Is it possible to achieve it in 1 command line?
If not the easiest way to do it?

2. Solution

Edit

1 liner cmd - ensure you are on MASTER branch

Above line will do exactly what you described in question.

Explanation:
Current state on remote repo:

First command
git remove all local branches except master

After this command local repo will looks:

Second command
git get all remote branches and refresh list in local repo of remote branches

After this command local repo will looks:

References

Edit
  1. Git branch - docs
  2. Git remote - docs
  3. xargs - linux docs

See also

Edit
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Git

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join