Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document negative refspec patterns #2025

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions book/10-git-internals/sections/refspec.asc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ From [email protected]:schacon/simplegit
In this case, the `master` branch pull was rejected because it wasn't listed as a fast-forward reference.
You can override that by specifying the `+` in front of the refspec.

[[_segmenting_refspecs]]
==== Segmenting Refspecs

You can also specify multiple refspecs for fetching in your configuration file.
If you want to always fetch the `master` and `experiment` branches from the `origin` remote, add two lines:

Expand All @@ -75,7 +78,7 @@ If you want to always fetch the `master` and `experiment` branches from the `ori
fetch = +refs/heads/experiment:refs/remotes/origin/experiment
----

Since Git 2.6.0 you can use partial globs in the pattern to match multiple branches, so this works:
Since Git 2.6.0, you can use partial globs in the pattern to match multiple branches, so this works:

[source,ini]
----
Expand All @@ -93,7 +96,19 @@ If you have a QA team that pushes a series of branches, and you want to get the
fetch = +refs/heads/qa/*:refs/remotes/origin/qa/*
----

If you have a complex workflow process that has a QA team pushing branches, developers pushing branches, and integration teams pushing and collaborating on remote branches, you can namespace them easily this way.
Since Git 2.29.0, you can also explicitly exclude patterns.
Negative refspecs start with a `^` and do not include the remote.
To get all the branches unless they start with an underscore, you can use config like this:

[source,ini]
----
[remote "origin"]
url = https://github.com/schacon/simplegit-progit
fetch = +refs/heads/*:refs/remotes/origin/*
fetch = ^refs/heads/_*
----

If you have a complex workflow process that has a QA team pushing branches, developers pushing branches, and integration teams pushing and collaborating on remote branches, you can manage them with patterns like these.

[[_pushing_refspecs]]
==== Pushing Refspecs
Expand Down