Difference between revisions of "Git"

From Jon's Wiki
 
(3 intermediate revisions by the same user not shown)
Line 91: Line 91:
 
   RewriteEngine On
 
   RewriteEngine On
 
   RewriteCond %{HTTPS} off
 
   RewriteCond %{HTTPS} off
   RedirectMatch 302 ^(?!/\.well-known/acme-challenge/).* <nowiki>https://</nowiki>git.'''mydomain.com'''$0
+
   RedirectMatch 301 ^(?!/\.well-known/acme-challenge/).* <nowiki>https://</nowiki>git.'''mydomain.com'''$0
 
   Alias "/.well-known/acme-challenge/" "/var/www/acme-challenges/"
 
   Alias "/.well-known/acme-challenge/" "/var/www/acme-challenges/"
 
  </VirtualHost>
 
  </VirtualHost>
Line 102: Line 102:
 
   Header always set Strict-Transport-Security "max-age=15768000"
 
   Header always set Strict-Transport-Security "max-age=15768000"
 
   
 
   
   ServerName git.jon.geek.nz
+
   ServerName git.'''mydomain.com'''
   ServerAdmin webmaster@jon.geek.nz
+
   ServerAdmin webmaster@'''mydomain.com'''
 
   
 
   
 
   ProxyRequests Off
 
   ProxyRequests Off
Line 112: Line 112:
 
   ErrorLog /var/log/apache2/gitea/error.log
 
   ErrorLog /var/log/apache2/gitea/error.log
 
   CustomLog /var/log/apache2/gitea/access.log combined
 
   CustomLog /var/log/apache2/gitea/access.log combined
</VirtualHost>
+
</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>