How to ignore some branches / tags copied to local git when git fetch --all

I have many remotes added to my git. Each console is a repository for one developer. Every day, I fetch --all to see any new branches that they create that they are ready to consider.

However, developers can push private branches to the remote. Say, all branches with an underscore prefix are not ready for viewing, and other branches are ready for viewing.

When executing git fetch --all graph of my git (via /libexec/git-core/git-gui ) will see all branches regardless of whether they have an underscore prefix or not. This complicates the schedule.

I want git fetch ignore those _XXXX branches from loading to local git. So when I look at the git graph, it looks like this:

  • Shows branches: RemoteA/Branch1 , RemoteB/Branch1 , RemoteB/Branch2
  • RemoteA/_Branch2 branches: RemoteA/_Branch2 , RemoteB/_Branch3

How can i do this?

+6
source share
4 answers

Instead of using the naming convention ' _ ', you can use namespaces by clicking a branch in origin/review/Branch1 ( git push Branch1:review/Branch1 )
(called "group" in this answer or "name of the hierarchical branch (the names of the slash branches) to which they respond )

Thus, you only need to get what is in the namespace "review":

 git fetch +refs/heads/review/*:refs/remotes/origin/review/* 

The only other option would be a script that:

+5
source

Having turned around on VonC answer with a special β€œbrowse” folder 1, you can change your .git/config entries for your employees' desks. Below is the relevant documentation.

Where was he once

 [remote "fred"] url = something.git fetch = +refs/heads/*:refs/remotes/fred/* 

You can change it to

 [remote "fred"] url = something.git fetch = +refs/heads/review/*:refs/remotes/fred/review/* fetch = +refs/heads/other_pattern/*:refs/remotes/fred/other_pattern/* fetch = +refs/heads/specific_branch:refs/remotes/fred/specific_branch 

After that, you may have to clear the links to links that you have already selected, but future git fetch --all or git fetch fred will not update anything outside of the patterns you specify.


1 Or as many special or interesting folders / branches as you need.

+3
source

You can do this in one step with an alias. Add this to your ~/.gitconfig file:

 [alias] fall = !sh -c 'git fetch --all && git branch -r | sed /HEAD/d | grep /_ | xargs git branch -dr' -- 

And then just say git fall . It will delete all deleted branches containing /_ .

You can observe the intricacies of aliases that are shell commands .: - /

+2
source

You can use the ignore-refs option:

 git fetch --ignore-refs branch123 
-1
source

Source: https://habr.com/ru/post/977394/


All Articles