Git: Difference between revisions
imported>Erikarvstedt m add reference to gitolite |
mNo edit summary |
||
| (17 intermediate revisions by 11 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 the Linux kernel). Git is used to maintain NixOS packages, as well as many other projects, including sources for the Linux kernel. | ||
== | == Installing and configuring Git == | ||
On NixOS, Git can be installed and configured at either the system level or the user level with [[Home Manager]]. | |||
=== | === System-wide installation === | ||
Git can be installed system-wide either by adding it to the list of system environment packages: | |||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | |||
environment.systemPackages = with pkgs; [ | |||
git | |||
]; | |||
</nowiki>}} | |||
Or by enabling the NixOS Git module: | |||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | |||
programs.git.enable = true; | |||
</nowiki>}} | |||
Additional Git module configuration options can be found at {{nixos:option|programs.git}}. | |||
{{note|Configuration options provided by this module are applied at the system level and therefore apply to all users on the system.}} | |||
== | === User-level configuration with Home Manager === | ||
Git can be configured using [[Home Manager]]: | Git can be configured using [[Home Manager]]: | ||
| Line 22: | Line 32: | ||
programs.git = { | programs.git = { | ||
enable = true; | enable = true; | ||
settings.user = { | |||
name = "John Doe"; | |||
email = "johndoe@example.com"; | |||
}; | |||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 32: | Line 44: | ||
programs.git = { | programs.git = { | ||
enable = true; | enable = true; | ||
settings.alias = { | |||
ci = "commit"; | ci = "commit"; | ||
co = "checkout"; | co = "checkout"; | ||
| Line 50: | Line 62: | ||
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> | |||
To add additional configuration you can specify options in an attribute set, so to add something like this: | |||
<syntaxhighlight lang="ini"> | <syntaxhighlight lang="ini"> | ||
| Line 72: | Line 81: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
To your <code>~/.config/git/config</code>, you can add the below to <code> | To your <code>~/.config/git/config</code>, you can add the below to <code>settings</code> | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
| Line 80: | Line 89: | ||
programs.git = { | programs.git = { | ||
enable = true; | enable = true; | ||
settings = { | |||
push = { autoSetupRemote = true; }; | push = { autoSetupRemote = true; }; | ||
}; | }; | ||
| Line 87: | Line 96: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== | ==== Using your public SSH key as a signing key ==== | ||
To 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> | |||
=== Enabling Git UI === | |||
Install <code>tk</code> to use the git gui: | |||
<syntaxhighlight lang=console> | |||
$ git citool | |||
</syntaxhighlight> | |||
<code> | Or you may wish to install the <code>gitFull</code> package, which includes <code>git gui</code>, <code>gitk</code>, etc. This can be installed either through system environment packages or by setting the package module option: | ||
= | <syntaxhighlight lang="nix"> | ||
programs.git = { | |||
enable = true; | |||
package = pkgs.gitFull; | |||
}; | |||
</syntaxhighlight> | |||
git | == Management of the <code>nixpkgs</code> git repository == | ||
<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. | |||
=== Garbage collecting === | |||
Normal <code>git gc</code> should work as usual, but you should force a full garbage collect every half a year or so. <code>git gc --aggressive</code> is the command for that. For the author it did not work on the first try, since their laptop’s memory was too small and it went out of memory. According to [https://stackoverflow.com/a/4829883/1382925|this StackOverflow] answer it suffices to set some local repository config variables. | Normal <code>git gc</code> should work as usual, but you should force a full garbage collect every half a year or so. <code>git gc --aggressive</code> is the command for that. For the author it did not work on the first try, since their laptop’s memory was too small and it went out of memory. According to [https://stackoverflow.com/a/4829883/1382925|this StackOverflow] answer it suffices to set some local repository config variables. | ||
| Line 149: | Line 201: | ||
<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 180: | Line 228: | ||
git push origin master | git push origin master | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Bisecting Nix regressions == | |||
{{main|bisecting}} | |||
[[Category:Applications]] | [[Category:Applications]] | ||
[[Category:CLI Applications]] | |||
[[Category:Version control]] | |||