Difference between revisions of "Git"
(11 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 Gitea == | ||
+ | |||
+ | [https://gitea.io/ Gitea] is an active fork of the quasi-abandoned Gogs project, and it is not currently packaged. It's a monolithic Go binary, so it's easy enough to stand up by following the [https://docs.gitea.io/en-us/install-from-binary/ binary install docs]. In sum, grab it (grab the .asc and verify with PGP): | ||
+ | |||
+ | wget -O /usr/local/bin/gitea <nowiki>https://dl.gitea.io/gitea/1.11.3/gitea-1.11.3-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/gitea/{custom,data,repositories} /var/log/gitea /etc/gitea | ||
+ | chown -R git:git /var/lib/gitea | ||
+ | chown git:adm /var/log/gitea | ||
+ | chown root:git /etc/gitea | ||
+ | chmod -R 750 /var/lib/gitea /var/log/gitea /etc/gitea | ||
+ | |||
+ | Edit <tt>/etc/systemd/system/gitea.service</tt> using the [https://github.com/go-gitea/gitea/blob/master/contrib/systemd/gitea.service example gitea.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/gitea/error.log | ||
+ | CustomLog /var/log/apache2/gitea/access.log combined | ||
+ | </VirtualHost> |
Latest revision as of 22:51, 14 December 2020
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 Gitea
Gitea is an active fork of the quasi-abandoned Gogs project, and it is not currently packaged. It's a monolithic Go binary, so it's 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/gitea https://dl.gitea.io/gitea/1.11.3/gitea-1.11.3-linux-amd64
Then install:
adduser --system --shell /bin/bash --gecos 'Git Version Control' --group --disabled-password --home /home/git git mkdir -p /var/lib/gitea/{custom,data,repositories} /var/log/gitea /etc/gitea chown -R git:git /var/lib/gitea chown git:adm /var/log/gitea chown root:git /etc/gitea chmod -R 750 /var/lib/gitea /var/log/gitea /etc/gitea
Edit /etc/systemd/system/gitea.service using the example gitea.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/gitea/error.log CustomLog /var/log/apache2/gitea/access.log combined </VirtualHost>