Difference between revisions of "Git"

From Jon's Wiki
Line 69: Line 69:
  
 
You're good to go!
 
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 [https://docs.gitea.io/en-us/install-from-binary/ binary install docs]. In sum, grab it and verify:
 +
 +
wget -O gitea https://dl.gitea.io/gitea/1.11.3/gitea-1.11.3-linux-amd64
 +
wget -O gitea.asc https://dl.gitea.io/gitea/1.11.3/gitea-1.11.3-linux-amd64.asc
 +
gpg --recv 7C9E68152594688862D62AF62D9AE806EC1592E2
 +
gpg --verify gitea.asc gitea
 +
mv gitea /usr/local/bin/
 +
 +
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
 +
mkdir /etc/gitea
 +
chown -R git:git /var/lib/gitea
 +
chown git:adm /var/log/gitea
 +
chmod -R 750 /var/lib/gitea /var/log/gitea
 +
chown root:git /etc/gitea
 +
chmod 770 /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 302 ^(?!/\.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.jon.geek.nz
 +
  ServerAdmin webmaster@jon.geek.nz
 +
 +
  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>

Revision as of 01:12, 26 March 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 and verify:

wget -O gitea https://dl.gitea.io/gitea/1.11.3/gitea-1.11.3-linux-amd64
wget -O gitea.asc https://dl.gitea.io/gitea/1.11.3/gitea-1.11.3-linux-amd64.asc
gpg --recv 7C9E68152594688862D62AF62D9AE806EC1592E2
gpg --verify gitea.asc gitea
mv gitea /usr/local/bin/

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
mkdir /etc/gitea
chown -R git:git /var/lib/gitea
chown git:adm /var/log/gitea
chmod -R 750 /var/lib/gitea /var/log/gitea
chown root:git /etc/gitea
chmod 770 /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 302 ^(?!/\.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.jon.geek.nz
  ServerAdmin webmaster@jon.geek.nz

  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>