Git: Difference between revisions
imported>Erikarvstedt mNo edit summary |
Replace deprecated extraConfig with settings |
||
| (15 intermediate revisions by 9 users not shown) | |||
| Line 1: | Line 1: | ||
[https://en.wikipedia.org/wiki/Git_(software) Git] is the version control system (VCS) designed | [https://en.wikipedia.org/wiki/Git_(software) Git] is the version control system (VCS) developed by Junio C Hamano and designed by Linus Torvalds (creator of linux kernel). Git is used to maintain NixOS packages, as well as many other projects, including sources for the Linux kernel. | ||
== Installation == | == Installation == | ||
| Line 16: | Line 16: | ||
== Configuration == | == Configuration == | ||
Git can be configured using [[Home Manager]]: | Git can be configured using [[Home Manager]]: | ||
| Line 22: | Line 21: | ||
programs.git = { | programs.git = { | ||
enable = true; | enable = true; | ||
settings.user = { | |||
name = "John Doe"; | |||
email = "johndoe@example.com"; | |||
}; | |||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 32: | Line 33: | ||
programs.git = { | programs.git = { | ||
enable = true; | enable = true; | ||
settings.alias = { | |||
ci = "commit"; | ci = "commit"; | ||
co = "checkout"; | co = "checkout"; | ||
| Line 50: | Line 51: | ||
Configure git-credential-helper with libsecret: | Configure git-credential-helper with libsecret: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix">{ pkgs, ... }: | ||
{ pkgs, ... }: | |||
{ | { | ||
programs.git = { | programs.git = { | ||
enable = true; | enable = true; | ||
package = pkgs.git.override { withLibsecret = true; }; | |||
settings = { | |||
credential.helper = "libsecret"; | |||
}; | }; | ||
}; | }; | ||
} | }</syntaxhighlight> | ||
</syntaxhighlight> | |||
For example to add additional configuration you can specify options in an attribute set, so to add something like this: | For example to add additional configuration you can specify options in an attribute set, so to add something like this: | ||
| Line 80: | Line 78: | ||
programs.git = { | programs.git = { | ||
enable = true; | enable = true; | ||
settings = { | |||
push = { autoSetupRemote = true; }; | push = { autoSetupRemote = true; }; | ||
}; | }; | ||
| Line 86: | Line 84: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Using your public SSH key as a signing key === | |||
You can naturally configure git to automatically sign your commits using your public SSH key like so:<syntaxhighlight lang="nix"> | |||
{ | |||
programs.git = { | |||
enable = true; | |||
signing = { | |||
key = "ssh-ed25519 AAAAAAAAAAAA...AA username@hostname"; | |||
signByDefault = true; | |||
}; | |||
settings = { | |||
gpg = { | |||
format = "ssh"; | |||
}; | |||
}; | |||
}; | |||
} | |||
</syntaxhighlight>However, note that this will also require Home Manager to manage your SSH configuration:<syntaxhighlight lang="nix">{ | |||
programs.ssh = { | |||
enable = true; | |||
addKeysToAgent = "yes"; | |||
}; | |||
}</syntaxhighlight> | |||
== Management of the <code>nixpkgs</code> git repository == | == Management of the <code>nixpkgs</code> git repository == | ||
<code>nixpkgs</code> has become a git repository of quite substantial size with > | <code>nixpkgs</code> has become a git repository of quite substantial size with > 889 000 commits (as of late 2025). This brings many unoptimized tools to their limits, leading to long waiting times on certain operations. Here we’ll collect useful info on how to manage that. | ||
=== git === | === git === | ||
| Line 109: | Line 130: | ||
This section implements [https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server Git on the Server - Setting Up the Server] on NixOS. | This section implements [https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server Git on the Server - Setting Up the Server] on NixOS. | ||
See also: [[gitolite]]. | |||
== Configuration == | == Configuration == | ||
| Line 147: | Line 170: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
sudo -u git bash -c | sudo -u git bash -c "git init --bare ~/myproject.git" | ||
</syntaxhighlight> | </syntaxhighlight> | ||
(<code>~</code> here is the home of the user <code>git</code>, which is <code>/var/lib/git-server</code>) | |||
2. Push to the server repo from another system | 2. Push to the server repo from another system | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
mkdir | mkdir myproject | ||
cd | cd myproject | ||
echo hello > a | echo hello > a | ||
git init | git init | ||
| Line 178: | Line 197: | ||
git push origin master | git push origin master | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Bisecting Nix regressions == | |||
see [[bisecting]] | |||
[[Category:Applications]] | [[Category:Applications]] | ||
[[Category:CLI Applications]] | |||
[[Category:Version control]] | |||