Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
67d9b39
breaking-changes: switch default branch to main
phillipwood Sep 10, 2025
877176e
t4013: switch default branch name to main
phillipwood Sep 10, 2025
3d6e7ec
t9902: switch default branch name to main
phillipwood Sep 10, 2025
5590b4e
t0613: stop setting default initial branch
phillipwood Sep 10, 2025
21a5f94
doc: git-checkout: clarify intro sentence
jvns Sep 10, 2025
ea03d5a
doc: git-checkout: clarify ARGUMENT DISAMBIGUATION
jvns Sep 10, 2025
ab215e4
doc: git-checkout: clarify `git checkout <branch>`
jvns Sep 10, 2025
042d6f3
doc: git-checkout: clarify `-b` and `-B`
jvns Sep 10, 2025
0dd71f6
doc: git-checkout: deduplicate --detach explanation
jvns Sep 10, 2025
bfe7b17
doc: git-checkout: split up restoring files section
jvns Sep 10, 2025
83a9405
doc: git-checkout: clarify restoring files section
jvns Sep 10, 2025
e7f04f6
t/unit-tests: update clar to fcbed04
pks-t Sep 10, 2025
e335ff3
Merge branch 'jk/add-i-color' into jk/color-variable-fixes
gitster Sep 16, 2025
3c3e9b8
color: use GIT_COLOR_* instead of numeric constants
peff Sep 16, 2025
53e8a43
color: return enum from git_config_colorbool()
peff Sep 16, 2025
8ee2476
grep: don't treat grep_opt.color as a strict bool
peff Sep 16, 2025
8efe643
diff: simplify color_moved check when flushing
peff Sep 16, 2025
4cfc971
diff: don't use diff_options.use_color as a strict bool
peff Sep 16, 2025
12df3c2
diff: pass o->use_color directly to fill_metainfo()
peff Sep 16, 2025
955000d
diff: stop passing ecbdata->use_color as boolean
peff Sep 16, 2025
5e9ddd3
pretty: use format_commit_context.auto_color as colorbool
peff Sep 16, 2025
e9330ae
color: use git_colorbool enum type to store colorbools
peff Sep 16, 2025
b978f78
color: return bool from want_color()
peff Sep 16, 2025
9d241b0
add-interactive: retain colorbool values longer
peff Sep 16, 2025
69a7e8d
config: store want_color() result in a separate bool
peff Sep 16, 2025
f448f65
send-email: don't duplicate Reply-to: in intro message
neilbrown Sep 17, 2025
3c07063
refs/files: catch conflicts on case-insensitive file-systems
KarthikNayak Sep 17, 2025
9b62a67
refs/files: use correct error type when lock exists
KarthikNayak Sep 17, 2025
770f389
refs/files: handle F/D conflicts in case-insensitive FS
KarthikNayak Sep 17, 2025
948b2ab
refs/files: handle D/F conflicts during locking
KarthikNayak Sep 17, 2025
e6c06e8
last-modified: fix bug when some paths remain unhandled
To1ne Sep 18, 2025
5b44c3b
rebase -i: respect commit.cleanup when picking fixups
phillipwood Sep 18, 2025
82a0a73
sequencer: remove VERBATIM_MSG flag
phillipwood Sep 18, 2025
373ad89
initial branch: give hints after switching the default name
gitster Sep 17, 2025
80bc042
t3903: reduce dependencies on previous tests
benknoble Sep 22, 2025
4b2de83
t3905: remove unneeded blank line
benknoble Sep 22, 2025
88b5b8d
stash: refactor private config globals
benknoble Sep 22, 2025
9842c0c
stash: honor stash.index in apply, pop modes
benknoble Sep 22, 2025
93dbb6b
t/unit-tests: update to 10e96bc
pks-t Sep 22, 2025
3ea35c6
stash: tell setup_revisions() to free our allocated strings
peff Sep 22, 2025
cd43948
revision: manage memory ownership of argv in setup_revisions()
peff Sep 19, 2025
f93c1d8
revision: add wrapper to setup_revisions() from a strvec
peff Sep 19, 2025
b553332
treewide: use setup_revisions_from_strvec() when we have a strvec
peff Sep 19, 2025
1806813
treewide: pass strvecs around for setup_revisions_from_strvec()
peff Sep 19, 2025
a04bc71
revision: retain argv NULL invariant in setup_revisions()
peff Sep 19, 2025
347af01
Merge branch 'ps/clar-updates'
gitster Sep 29, 2025
d235f69
Merge branch 'nb/send-email-no-dup-reply-to'
gitster Sep 29, 2025
e50c3ca
Merge branch 'pw/3.0-default-initial-branch-to-main'
gitster Sep 29, 2025
d960d6a
Merge branch 'jc/3.0-default-initial-branch-to-main-addendum'
gitster Sep 29, 2025
84edf99
Merge branch 'pw/rebase-i-cleanup-fix'
gitster Sep 29, 2025
4bac57b
Merge branch 'jk/setup-revisions-freefix'
gitster Sep 29, 2025
cff1e3c
Merge branch 'je/doc-checkout'
gitster Sep 29, 2025
a5d4779
Merge branch 'dk/stash-apply-index'
gitster Sep 29, 2025
a89fa2f
Merge branch 'jk/color-variable-fixes'
gitster Sep 29, 2025
96ed0a8
Merge branch 'kn/refs-files-case-insensitive'
gitster Sep 29, 2025
d5518d5
Merge branch 'tc/last-modified-recursive-fix'
gitster Sep 29, 2025
821f583
The thirteenth batcn
gitster Sep 29, 2025
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
6 changes: 6 additions & 0 deletions Documentation/BreakingChanges.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ A prerequisite for this change is that the ecosystem is ready to support the
"reftable" format. Most importantly, alternative implementations of Git like
JGit, libgit2 and Gitoxide need to support it.

* In new repositories, the default branch name will be `main`. We have been
warning that the default name will change since 675704c74dd (init:
provide useful advice about init.defaultBranch, 2020-12-11). The new name
matches the default branch name used in new repositories by many of the
big Git forges.

=== Removals

* Support for grafting commits has long been superseded by git-replace(1).
Expand Down
42 changes: 42 additions & 0 deletions Documentation/RelNotes/2.52.0.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ UI, Workflows & Features
allow the "partialCloneFilter" settings and the "token" value to be
communicated from the server side.

* Declare that "git init" that is not otherwise configured uses
'main' as the initial branch, not 'master', starting Git 3.0.

* Keep giving hint about the default initial branch name for users
who may be surprised after Git 3.0 switch-over.

* The stash.index configuration variable can be set to make "git stash
pop/apply" pretend that it was invoked with "--index".


Performance, Internal Implementation, Development Support etc.
--------------------------------------------------------------
Expand Down Expand Up @@ -87,6 +96,12 @@ Performance, Internal Implementation, Development Support etc.
* "git range-diff" learned a way to limit the memory consumed by
O(N*N) cost matrix.

* Some places in the code confused a variable that is *not* a boolean
to enable color but is an enum that records what the user requested
to do about color. A couple of bugs of this sort have been fixed,
while the code has been cleaned up to prevent similar bugs in the
future.


Fixes since v2.51
-----------------
Expand Down Expand Up @@ -217,6 +232,33 @@ including security updates, are included in this release.
* "git subtree" (in contrib/) did not work correctly when splitting
squashed subtrees, which has been improved.

* Import a newer version of the clar unit testing framework.
(merge 93dbb6b3c5 ps/clar-updates later to maint).

* "git send-email --compose --reply-to=<address>" used to add
duplicated Reply-To: header, which made mailservers unhappy. This
has been corrected.
(merge f448f65719 nb/send-email-no-dup-reply-to later to maint).

* "git rebase -i" failed to clean-up the commit log message when the
command commits the final one in a chain of "fixup" commands, which
has been corrected.
(merge 82a0a73e15 pw/rebase-i-cleanup-fix later to maint).

* There are double frees and leaks around setup_revisions() API used
in "git stash show", which has been fixed, and setup_revisions()
API gained a wrapper to make it more ergonomic when using it with
strvec-manged argc/argv pairs.
(merge a04bc71725 jk/setup-revisions-freefix later to maint).

* Deal more gracefully with directory / file conflicts when the files
backend is used for ref storage, by failing only the ones that are
involved in the conflict while allowing others.
(merge 948b2ab0d8 kn/refs-files-case-insensitive later to maint).

* "git last-modified" operating in non-recursive mode used to trigger
a BUG(), which has been corrected.

* Other code cleanup, docfix, build fix, etc.
(merge 823d537fa7 kh/doc-git-log-markup-fix later to maint).
(merge cf7efa4f33 rj/t6137-cygwin-fix later to maint).
Expand Down
5 changes: 5 additions & 0 deletions Documentation/config/stash.adoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
stash.index::
If this is set to true, `git stash apply` and `git stash pop` will
behave as if `--index` was supplied. Defaults to false. See the
descriptions in linkgit:git-stash[1].

stash.showIncludeUntracked::
If this is set to true, the `git stash show` command will show
the untracked files of a stash entry. Defaults to false. See
Expand Down
151 changes: 76 additions & 75 deletions Documentation/git-checkout.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,29 @@ git checkout [-q] [-f] [-m] [<branch>]
git checkout [-q] [-f] [-m] --detach [<branch>]
git checkout [-q] [-f] [-m] [--detach] <commit>
git checkout [-q] [-f] [-m] [[-b|-B|--orphan] <new-branch>] [<start-point>]
git checkout [-f] <tree-ish> [--] <pathspec>...
git checkout [-f] <tree-ish> --pathspec-from-file=<file> [--pathspec-file-nul]
git checkout <tree-ish> [--] <pathspec>...
git checkout <tree-ish> --pathspec-from-file=<file> [--pathspec-file-nul]
git checkout [-f|--ours|--theirs|-m|--conflict=<style>] [--] <pathspec>...
git checkout [-f|--ours|--theirs|-m|--conflict=<style>] --pathspec-from-file=<file> [--pathspec-file-nul]
git checkout (-p|--patch) [<tree-ish>] [--] [<pathspec>...]

DESCRIPTION
-----------
Updates files in the working tree to match the version in the index
or the specified tree. If no pathspec was given, `git checkout` will
also update `HEAD` to set the specified branch as the current
branch.

`git checkout` has two main modes:

1. **Switch branches**, with `git checkout <branch>`
2. **Restore a different version of a file**, for example with
`git checkout <commit> <filename>` or `git checkout <filename>`

See ARGUMENT DISAMBIGUATION below for how Git decides which one to do.

`git checkout [<branch>]`::
To prepare for working on _<branch>_, switch to it by updating
the index and the files in the working tree, and by pointing
`HEAD` at the branch. Local modifications to the files in the
working tree are kept, so that they can be committed to the
_<branch>_.
Switch to _<branch>_. This sets the current branch to _<branch>_ and
updates the files in your working directory. The checkout will fail
if there are uncommitted changes to any files where _<branch>_ and
your current commit have different content. Uncommitted changes will
otherwise be kept.
+
If _<branch>_ is not found but there does exist a tracking branch in
exactly one remote (call it _<remote>_) with a matching name and
Expand All @@ -40,68 +44,63 @@ exactly one remote (call it _<remote>_) with a matching name and
$ git checkout -b <branch> --track <remote>/<branch>
------------
+
You could omit _<branch>_, in which case the command degenerates to
"check out the current branch", which is a glorified no-op with
rather expensive side-effects to show only the tracking information,
if it exists, for the current branch.

`git checkout (-b|-B) <new-branch> [<start-point>]`::

Specifying `-b` causes a new branch to be created as if
linkgit:git-branch[1] were called and then checked out. In
this case you can use the `--track` or `--no-track` options,
which will be passed to `git branch`. As a convenience,
`--track` without `-b` implies branch creation; see the
description of `--track` below.
+
If `-B` is given, _<new-branch>_ is created if it doesn't exist; otherwise, it
is reset. This is the transactional equivalent of
+
------------
$ git branch -f <branch> [<start-point>]
$ git checkout <branch>
------------
Running `git checkout` without specifying a branch has no effect except
to print out the tracking information for the current branch.

`git checkout -b <new-branch> [<start-point>]`::

Create a new branch named _<new-branch>_, start it at _<start-point>_
(defaults to the current commit), and check out the new branch.
You can use the `--track` or `--no-track` options to set the branch's
upstream tracking information.
+
that is to say, the branch is not reset/created unless "git checkout" is
successful (e.g., when the branch is in use in another worktree, not
just the current branch stays the same, but the branch is not reset to
the start-point, either).
This will fail if there's an error checking out _<new-branch>_, for
example if checking out the `<start-point>` commit would overwrite your
uncommitted changes.

`git checkout -B <branch> [<start-point>]`::

The same as `-b`, except that if the branch already exists it
resets `_<branch>_` to the start point instead of failing.

`git checkout --detach [<branch>]`::
`git checkout [--detach] <commit>`::

Prepare to work on top of _<commit>_, by detaching `HEAD` at it
(see "DETACHED HEAD" section), and updating the index and the
files in the working tree. Local modifications to the files
in the working tree are kept, so that the resulting working
tree will be the state recorded in the commit plus the local
modifications.
+
When the _<commit>_ argument is a branch name, the `--detach` option can
be used to detach `HEAD` at the tip of the branch (`git checkout
<branch>` would check out that branch without detaching `HEAD`).
The same as `git checkout <branch>`, except that instead of pointing
`HEAD` at the branch, it points `HEAD` at the commit ID.
See the "DETACHED HEAD" section below for more.
+
Omitting _<branch>_ detaches `HEAD` at the tip of the current branch.

`git checkout [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <pathspec>...`::
`git checkout [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] --pathspec-from-file=<file> [--pathspec-file-nul]`::
`git checkout <tree-ish> [--] <pathspec>...`::
`git checkout <tree-ish> --pathspec-from-file=<file> [--pathspec-file-nul]`::

Overwrite the contents of the files that match the pathspec.
When the _<tree-ish>_ (most often a commit) is not given,
overwrite working tree with the contents in the index.
When the _<tree-ish>_ is given, overwrite both the index and
the working tree with the contents at the _<tree-ish>_.
Replace the specified files and/or directories with the version from
the given commit or tree and add them to the index
(also known as "staging area").
+
The index may contain unmerged entries because of a previous failed merge.
By default, if you try to check out such an entry from the index, the
checkout operation will fail and nothing will be checked out.
Using `-f` will ignore these unmerged entries. The contents from a
specific side of the merge can be checked out of the index by
using `--ours` or `--theirs`. With `-m`, changes made to the working tree
file can be discarded to re-create the original conflicted merge result.
For example, `git checkout main file.txt` will replace `file.txt`
with the version from `main`.

`git checkout [-f|--ours|--theirs|-m|--conflict=<style>] [--] <pathspec>...`::
`git checkout [-f|--ours|--theirs|-m|--conflict=<style>] --pathspec-from-file=<file> [--pathspec-file-nul]`::

Replace the specified files and/or directories with the version from
the index.
+
For example, if you check out a commit, edit `file.txt`, and then
decide those changes were a mistake, `git checkout file.txt` will
discard any unstaged changes to `file.txt`.
+
This will fail if the file has a merge conflict and you haven't yet run
`git add file.txt` (or something equivalent) to mark it as resolved.
You can use `-f` to ignore the unmerged files instead of failing, use
`--ours` or `--theirs` to replace them with the version from a specific
side of the merge, or use `-m` to replace them with the original
conflicted merge result.

`git checkout (-p|--patch) [<tree-ish>] [--] [<pathspec>...]`::
This is similar to the previous mode, but lets you use the
This is similar to the previous two modes, but lets you use the
interactive interface to show the "diff" output and choose which
hunks to use in the result. See below for the description of
`--patch` option.
Expand Down Expand Up @@ -155,16 +154,14 @@ of it").
see linkgit:git-branch[1] for details.

`-B <new-branch>`::
Creates the branch _<new-branch>_, start it at _<start-point>_;
if it already exists, then reset it to _<start-point>_. And then
check the resulting branch out. This is equivalent to running
`git branch` with `-f` followed by `git checkout` of that branch;
see linkgit:git-branch[1] for details.
The same as `-b`, except that if the branch already exists it
resets `_<branch>_` to the start point instead of failing.

`-t`::
`--track[=(direct|inherit)]`::
When creating a new branch, set up "upstream" configuration. See
`--track` in linkgit:git-branch[1] for details.
`--track` in linkgit:git-branch[1] for details. As a convenience,
--track without -b implies branch creation.
+
If no `-b` option is given, the name of the new branch will be
derived from the remote-tracking branch, by looking at the local part of
Expand Down Expand Up @@ -511,14 +508,18 @@ $ git log -g -2 HEAD
ARGUMENT DISAMBIGUATION
-----------------------

When there is only one argument given and it is not `--` (e.g. `git
checkout abc`), and when the argument is both a valid _<tree-ish>_
(e.g. a branch `abc` exists) and a valid _<pathspec>_ (e.g. a file
or a directory whose name is "abc" exists), Git would usually ask
you to disambiguate. Because checking out a branch is so common an
operation, however, `git checkout abc` takes "abc" as a _<tree-ish>_
in such a situation. Use `git checkout -- <pathspec>` if you want
to checkout these paths out of the index.
When you run `git checkout <something>`, Git tries to guess whether
`<something>` is intended to be a branch, a commit, or a set of file(s),
and then either switches to that branch or commit, or restores the
specified files.

If there's any ambiguity, Git will treat `<something>` as a branch or
commit, but you can use the double dash `--` to force Git to treat the
parameter as a list of files and/or directories, like this:

----------
git checkout -- file.txt
----------

EXAMPLES
--------
Expand Down
12 changes: 9 additions & 3 deletions Documentation/git-init.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,15 @@ If this is a reinitialization, the repository will be moved to the specified pat
`-b <branch-name>`::
`--initial-branch=<branch-name>`::
Use _<branch-name>_ for the initial branch in the newly created
repository. If not specified, fall back to the default name (currently
`master`, but this is subject to change in the future; the name can be
customized via the `init.defaultBranch` configuration variable).
repository. If not specified, fall back to the default name
ifndef::with-breaking-changes[]
(currently `master`, but this will change to `main` when Git 3.0 is released).
endif::with-breaking-changes[]
ifdef::with-breaking-changes[]
`main`.
endif::with-breaking-changes[]
The default name can be customized via the `init.defaultBranch` configuration
variable.

`--shared[=(false|true|umask|group|all|world|everybody|<perm>)]`::

Expand Down
25 changes: 13 additions & 12 deletions add-interactive.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
#include "prompt.h"
#include "tree.h"

static void init_color(struct repository *r, int use_color,
static void init_color(struct repository *r, enum git_colorbool use_color,
const char *section_and_slot, char *dst,
const char *default_color)
{
char *key = xstrfmt("color.%s", section_and_slot);
const char *value;

if (!use_color)
if (!want_color(use_color))
dst[0] = '\0';
else if (repo_config_get_value(r, key, &value) ||
color_parse(value, dst))
Expand All @@ -36,13 +36,13 @@ static void init_color(struct repository *r, int use_color,
free(key);
}

static int check_color_config(struct repository *r, const char *var)
static enum git_colorbool check_color_config(struct repository *r, const char *var)
{
const char *value;
int ret;
enum git_colorbool ret;

if (repo_config_get_value(r, var, &value))
ret = -1;
ret = GIT_COLOR_UNKNOWN;
else
ret = git_config_colorbool(var, value);

Expand All @@ -51,10 +51,11 @@ static int check_color_config(struct repository *r, const char *var)
* the value parsed by git_color_config(), which may not have been
* called by the main command.
*/
if (ret < 0 && !repo_config_get_value(r, "color.ui", &value))
if (ret == GIT_COLOR_UNKNOWN &&
!repo_config_get_value(r, "color.ui", &value))
ret = git_config_colorbool("color.ui", value);

return want_color(ret);
return ret;
}

void init_add_i_state(struct add_i_state *s, struct repository *r,
Expand All @@ -75,7 +76,7 @@ void init_add_i_state(struct add_i_state *s, struct repository *r,
init_color(r, s->use_color_interactive, "interactive.error",
s->error_color, GIT_COLOR_BOLD_RED);
strlcpy(s->reset_color_interactive,
s->use_color_interactive ? GIT_COLOR_RESET : "", COLOR_MAXLEN);
want_color(s->use_color_interactive) ? GIT_COLOR_RESET : "", COLOR_MAXLEN);

s->use_color_diff = check_color_config(r, "color.diff");

Expand All @@ -92,7 +93,7 @@ void init_add_i_state(struct add_i_state *s, struct repository *r,
init_color(r, s->use_color_diff, "diff.new", s->file_new_color,
diff_get_color(s->use_color_diff, DIFF_FILE_NEW));
strlcpy(s->reset_color_diff,
s->use_color_diff ? GIT_COLOR_RESET : "", COLOR_MAXLEN);
want_color(s->use_color_diff) ? GIT_COLOR_RESET : "", COLOR_MAXLEN);

FREE_AND_NULL(s->interactive_diff_filter);
repo_config_get_string(r, "interactive.difffilter",
Expand Down Expand Up @@ -130,8 +131,8 @@ void clear_add_i_state(struct add_i_state *s)
FREE_AND_NULL(s->interactive_diff_filter);
FREE_AND_NULL(s->interactive_diff_algorithm);
memset(s, 0, sizeof(*s));
s->use_color_interactive = -1;
s->use_color_diff = -1;
s->use_color_interactive = GIT_COLOR_UNKNOWN;
s->use_color_diff = GIT_COLOR_UNKNOWN;
}

/*
Expand Down Expand Up @@ -1210,7 +1211,7 @@ int run_add_i(struct repository *r, const struct pathspec *ps,
* When color was asked for, use the prompt color for
* highlighting, otherwise use square brackets.
*/
if (s.use_color_interactive) {
if (want_color(s.use_color_interactive)) {
data.color = s.prompt_color;
data.reset = s.reset_color_interactive;
}
Expand Down
Loading