Difference between revisions of "Git"
| (14 intermediate revisions by the same user not shown) | |||
| Line 5: | Line 5: | ||
[alias] | [alias] | ||
lol = log --graph --decorate --oneline | lol = log --graph --decorate --oneline | ||
| + | cdiff = diff --word-diff-regex=. | ||
| + | cshow = show --word-diff-regex=. | ||
| + | wdiff = diff --word-diff-regex=[^[:space:]]+ | ||
| + | wshow = show --word-diff-regex=[^[:space:]]+ [color] | ||
[color] | [color] | ||
diff = auto | diff = auto | ||
| Line 34: | Line 38: | ||
== Track Mercurial transparently with git == | == Track Mercurial transparently with git == | ||
| − | To track a project hosted in a | + | To track a project hosted in a Mercurial repository, we can use the nifty hg-fast-export package. Install Mercurial and its fast export: |
sudo apt-get install mercurial hg-fast-export | sudo apt-get install mercurial hg-fast-export | ||
| Line 40: | Line 44: | ||
Use the Mercurial subcommand to clone your upstream Mercurial repository (Note the // in the path) into git. | Use the Mercurial subcommand to clone your upstream Mercurial repository (Note the // in the path) into git. | ||
| − | git hg clone | + | git hg clone <nowiki>ssh://jack@beanstalk.net//var/lib/mercurial/magicbeans</nowiki> |
Updating is easy: | Updating is easy: | ||
| Line 65: | Line 69: | ||
You're good to go! | You're good to go! | ||
| + | |||
| + | == Installing Forgejo == | ||
| + | |||
| + | [https://forgejo.org/ Forgejo] is a [https://forgejo.org/2022-12-15-hello-forgejo/ community fork] of Gitea, which itself forked the quasi-abandoned Gogs project. It is not currently packaged, but it is a monolithic Go binary and therefore easy enough to stand up by following the [https://forgejo.org/docs/latest/admin/installation-binary/ binary install docs]. In sum, grab it (grab the .asc and verify with PGP): | ||
| + | |||
| + | wget -O /usr/local/bin/forgejo <nowiki>https://codeberg.org/forgejo/forgejo/releases/download/v10.0.1/forgejo-10.0.1-linux-amd64</nowiki> | ||
| + | |||
| + | Then install: | ||
| + | |||
| + | adduser --system --shell /bin/bash --gecos 'Git Version Control' --group --disabled-password --home /home/git git | ||
| + | mkdir -p /var/lib/forgejo/{custom,data,repositories} /var/log/forgejo /etc/forgejo | ||
| + | chown -R git:git /var/lib/forgejo | ||
| + | chown git:adm /var/log/forgejo | ||
| + | chown root:git /etc/forgejo | ||
| + | chmod -R 750 /var/lib/forgejo /var/log/forgejo /etc/forgejo | ||
| + | |||
| + | Edit <tt>/etc/systemd/system/forgejo.service</tt> using the [https://codeberg.org/forgejo/forgejo/src/branch/forgejo/contrib/systemd/forgejo.service example forgejo.service file] from the documentation as a guide. Set up an Apache or Nginx proxy definition: | ||
| + | |||
| + | <VirtualHost *:80> | ||
| + | ServerName git.'''mydomain.com''' | ||
| + | RewriteEngine On | ||
| + | RewriteCond %{HTTPS} off | ||
| + | RedirectMatch 301 ^(?!/\.well-known/acme-challenge/).* <nowiki>https://</nowiki>git.'''mydomain.com'''$0 | ||
| + | Alias "/.well-known/acme-challenge/" "/var/www/acme-challenges/" | ||
| + | </VirtualHost> | ||
| + | |||
| + | <VirtualHost *:443> | ||
| + | SSLEngine On | ||
| + | SSLCertificateFile /etc/ssl/letsencrypt/git.'''mydomain.com'''/cert.pem | ||
| + | SSLCertificateChainFile /etc/ssl/letsencrypt/git.'''mydomain.com'''/chain.pem | ||
| + | SSLCertificateKeyFile /etc/ssl/letsencrypt/git.'''mydomain.com'''/privkey.pem | ||
| + | Header always set Strict-Transport-Security "max-age=15768000" | ||
| + | |||
| + | ServerName git.'''mydomain.com''' | ||
| + | ServerAdmin webmaster@'''mydomain.com''' | ||
| + | |||
| + | ProxyRequests Off | ||
| + | ProxyPreserveHost On | ||
| + | ProxyPass / <nowiki>http://localhost:3000/</nowiki> | ||
| + | ProxyPassReverse / <nowiki>http://localhost:3000/</nowiki> | ||
| + | |||
| + | ErrorLog /var/log/apache2/forgejo/error.log | ||
| + | CustomLog /var/log/apache2/forgejo/access.log combined | ||
| + | </VirtualHost> | ||
| + | |||
| + | === Updating Forgejo versions === | ||
| + | |||
| + | sudo -u git forgejo --config /etc/forgejo/app.ini doctor check --all --log-file /tmp/doctor.log | ||
| + | # fix any errors | ||
| + | sudo -u git forgejo --config /etc/forgejo/app.ini manager flush-queues | ||
| + | wget <nowiki>https://codeberg.org/forgejo/.../forgejo-''latest''-linux-amd64</nowiki> | ||
| + | mv forgejo-''latest''-linux-amd64 /var/lib/forgejo/bin | ||
| + | chmod +x /var/lib/forgejo/bin/forgejo-''latest''-linux-amd64 | ||
| + | systemctl stop forgejo.service | ||
| + | ln -sf /var/lib/forgejo/bin/forgejo-''latest''-linux-amd64 /usr/local/bin/forgejo | ||
| + | sudo -u git forgejo --config /etc/forgejo/app.ini migrate | ||
| + | sudo -u git forgejo --config /etc/forgejo/app.ini doctor check --all --log-file /tmp/doctor.log | ||
| + | # fix any errors | ||
| + | systemctl start forgejo.service | ||
Latest revision as of 00:24, 3 March 2025
Handy git configuration
Put this in your ~/.gitconfig
[alias]
lol = log --graph --decorate --oneline
cdiff = diff --word-diff-regex=.
cshow = show --word-diff-regex=.
wdiff = diff --word-diff-regex=[^[:space:]]+
wshow = show --word-diff-regex=[^[:space:]]+ [color]
[color]
diff = auto
branch = auto
log = auto
status = auto
[push]
default = current
[user]
name = Harry Potter
email = harry@hogwarts.school.uk
[core]
autocrlf = input
pager = less -F -X
Bung these in your ~/.bashrc
export GIT_AUTHOR_NAME='Harry Potter' export GIT_AUTHOR_EMAIL='harry@hogwarts.school.uk' export GIT_COMMITTER_NAME=$GIT_AUTHOR_NAME export GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL export GIT_PS1_SHOWDIRTYSTATE=1 export GIT_PS1_SHOWUNTRACKEDFILES=1 export GIT_PS1_SHOWUPSTREAM=auto # very handy to have your git branch and checkout status in your prompt: export PS1='\[\e[1m\]\u@\h:\w\[\e[32;1m\]$(__git_ps1 "(%s)")\[\e[m\e[1m\]\$\[\e[m\] '
Track Mercurial transparently with git
To track a project hosted in a Mercurial repository, we can use the nifty hg-fast-export package. Install Mercurial and its fast export:
sudo apt-get install mercurial hg-fast-export
Use the Mercurial subcommand to clone your upstream Mercurial repository (Note the // in the path) into git.
git hg clone ssh://jack@beanstalk.net//var/lib/mercurial/magicbeans
Updating is easy:
cd magicbeans git hg fetch
Importing a CVS project from SourceForge into git
First, grab a clone of the remote CVS repository. The easiest way to do this with a SourceForge project, without having to actually use CVS and its pserver logins and whatnot, is to use rsync:
rsync -avz rsync://meta-extractor.cvs.sourceforge.net/cvsroot/meta-extractor cvs-clone
Now we're going to import the history of the relevant CVS module (in this case, "metadata-extractor") into a new git repository.
sudo apt-get install git-cvsimport git cvsimport -C meta-extractor.git -p x -v -d $(pwd)/cvs-clone metadata-extractor
Now you can push your new git project to Github or somewhere:
cd meta-extractor.git git remote add origin <your-new-git-repo> git push --tags master
You're good to go!
Installing Forgejo
Forgejo is a community fork of Gitea, which itself forked the quasi-abandoned Gogs project. It is not currently packaged, but it is a monolithic Go binary and therefore easy enough to stand up by following the binary install docs. In sum, grab it (grab the .asc and verify with PGP):
wget -O /usr/local/bin/forgejo https://codeberg.org/forgejo/forgejo/releases/download/v10.0.1/forgejo-10.0.1-linux-amd64
Then install:
adduser --system --shell /bin/bash --gecos 'Git Version Control' --group --disabled-password --home /home/git git
mkdir -p /var/lib/forgejo/{custom,data,repositories} /var/log/forgejo /etc/forgejo
chown -R git:git /var/lib/forgejo
chown git:adm /var/log/forgejo
chown root:git /etc/forgejo
chmod -R 750 /var/lib/forgejo /var/log/forgejo /etc/forgejo
Edit /etc/systemd/system/forgejo.service using the example forgejo.service file from the documentation as a guide. Set up an Apache or Nginx proxy definition:
<VirtualHost *:80>
ServerName git.mydomain.com
RewriteEngine On
RewriteCond %{HTTPS} off
RedirectMatch 301 ^(?!/\.well-known/acme-challenge/).* https://git.mydomain.com$0
Alias "/.well-known/acme-challenge/" "/var/www/acme-challenges/"
</VirtualHost>
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /etc/ssl/letsencrypt/git.mydomain.com/cert.pem
SSLCertificateChainFile /etc/ssl/letsencrypt/git.mydomain.com/chain.pem
SSLCertificateKeyFile /etc/ssl/letsencrypt/git.mydomain.com/privkey.pem
Header always set Strict-Transport-Security "max-age=15768000"
ServerName git.mydomain.com
ServerAdmin webmaster@mydomain.com
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
ErrorLog /var/log/apache2/forgejo/error.log
CustomLog /var/log/apache2/forgejo/access.log combined
</VirtualHost>
Updating Forgejo versions
sudo -u git forgejo --config /etc/forgejo/app.ini doctor check --all --log-file /tmp/doctor.log # fix any errors sudo -u git forgejo --config /etc/forgejo/app.ini manager flush-queues wget https://codeberg.org/forgejo/.../forgejo-''latest''-linux-amd64 mv forgejo-latest-linux-amd64 /var/lib/forgejo/bin chmod +x /var/lib/forgejo/bin/forgejo-latest-linux-amd64 systemctl stop forgejo.service ln -sf /var/lib/forgejo/bin/forgejo-latest-linux-amd64 /usr/local/bin/forgejo sudo -u git forgejo --config /etc/forgejo/app.ini migrate sudo -u git forgejo --config /etc/forgejo/app.ini doctor check --all --log-file /tmp/doctor.log # fix any errors systemctl start forgejo.service