2.9 KiB
General
GIT is a version control software, that allows you to save the progress of software/text/whatever development. It is probably best know from GitHub, but we will show how to set up your own GIT instance and how to use it.
Installing GIT
What you need
- A working server, being it self-hosted at home or a remote instance, called REMOTE in the following
- A local machine that you develop whatever on, called LOCAL in the following
Installing GIT
On the LOCAL machine, use your favorite package manager, for example
pacman -S git
The same holds for the REMOTE machine, but here I would advice, to use some LTS distro, so probably
sudo apt install git
Setting up the Server
First we have to add the git-user on the REMOTE, give him a password and enable ssh logins.
sudo adduser git
su git
passwd
cd
mkdir .ssh & chmod 700 .ssh
touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys
Now add the ssh public keys of your LOCAL machine to the authorized_keys
file on the REMOTE.
For this on the LOCAL machine generate a key-pair using ssh-keygen -t rsa
if you don't have one yet.
Then copy the content of LOCAL/.ssh/id_rsa.pub
to the REMOTE/.ssh/authorized_keys
file.
New Repository
To initialize a repository on the REMOTE server we have to create a new folder and tell git to track this folder. This has to be done once for every new repository.
cd
mkdir NewRepo.git
cd NewRepo.git
git init --bare
On the LOCAL machine we then have to create a folder and tell git to sync this with the server.
We will assume that REMOTE
is either the IP or the domain-name of the REMOTE instance.
cd project
git init
git add .
git commit -m 'Initial commit'
git remote add origin git@REMOTE:/home/git/NewRepo.git
git push origin master
Using Git
To now sync this folder to other devices use
git clone git@gitserver:/home/git/NewRepo.git
cd project
To update the repository go to the folder, add the necessary files using git add <FILES>
and then commit them using git commit -m '<MESSAGE>
. These steps can be done as one using
git commit -am 'Fix for README file'
Now push it to the server using git push origin master
.
Branches
To create a new branch, use git checkout -b <BRANCHNAME>
.
To push this to the remote location, use git push origin <BRANCHNAME>
.
Configuration
Pass integration
pass is a CLI password manager. It allows for git integration.
First, install pass-git-helper
from the AUR
paru -S pass-git-helper
Set pass as your credential helper in git:
git config --global credential.helper /usr/bin/pass-git-helper
In ~/.config/pass-git-helper/git-pass-mapping.ini
, create rules in the following way:
[github.com]
target=dev/github
[*.fooo-bar.*]
target=dev/fooo-bar