Git - the Default Version Control
Git is one of the fundamental tool any homelabber needs. Git repositories can be on site, but better off site on GitLab or GitHub. Some stuff needs to be on local servers and can easily by self hosted or just local. #git
Creating stuff you need Version Control and also some backup against breaking SSD's. This is not all git do but these are the basic functions you need on a daily basis, working alone or part of a team or a network of teams.
Git is easy to use from the CLI, Tmux or VS Code or any platform you like. It even has some GUI apps you may be interested in.
40+ years of dealing with version control systems I've seen and experienced the bad, the good and the ugly. Git is my all time favorite.
My first experience with version control is back over 40 years ago and wasn't the best. Working in a global team spanning teams in Europe, US, Taiwan and Japan the coordination of the effort was essential - you needed to continue where the other team left it and document every thing for the next team who toke it on after you. It was interesting to start your morning by looking on what progress the previous teams had done on your part of the project and to read the status of the over all progress. This way all continents was involved and the project run 24 h a day. It was a great time with basic tools. Yes we had email and access to global networks back then - before www was a thing.
History of Git - Wikipedia
Git (/ɡɪt/) is a distributed version control system that tracks changes in any set of computer files, usually used for coordinating work among programmers who are collaboratively developing source code during software development. Its goals include speed, data integrity, and support for distributed, non-linear workflows (thousands of parallel branches running on different computers).[10][11][12]
Git was originally authored by Linus Torvalds in 2005 for development of the Linux kernel, with other kernel developers contributing to its initial development. Since 2005, Junio Hamano has been the core maintainer. As with most other distributed version control systems, and unlike most client–server systems, every Git directory on every computer is a full-fledged repository with complete history and full version-tracking abilities, independent of network access or a central server. Git is free and open-source software shared under the GPL-2.0-only license.
Since its creation, Git has become the most popular distributed version control system, with nearly 95% of developers reporting it as their primary version control system as of 2022. There are many popular offerings of Git repository services, including GitHub, SourceForge, Bitbucket and GitLab.
Installation
Git needs to be installed on your machine. You need git on your machine, some keys and a repository (self-hosted or even better use GitLab or GitHub). SSH will be the tool you use in many instances and for many tasks. Make sure you have it.
Install git
sudo apt-get update && sudo apt-get install -y git
Create your keys
Use a key with a passphrase for better security - if feasible
There is many types of keys but today the de-facto standard is ed25519.
To copy it to any of your servers type ssh-copy-id -i <key.pub> <serverIP> and it will be added to the .ssh/authorized_keys file on the server.
ssh-copy-id -i ~/.ssh/id_ed25519.pub 192.0.2.123
Sometimes you need a key without a passphrase for things like Ansible. You can use passphrases with Ansible if you set it up like that. You upload this one to the the servers Ansible controls.
SSH Agent
You can use many things to automate ssh like ssh-agen and ssh-config. The Agent keeps your passphrase in memory as long as your session is active, eval$(ssh/agent)
and add your passphrase to the cache running in the background by ssh-add
. By adding an alias to your bash/zsh/fish -personal file you will make it easier alias ssha='eval $(ssh-agent) && ssh-add
.
SSH Config
SSH config another fantastic little tool to use. After copying the public key to your servers you create the config file. nano .ssh/config
AddKeysToAgent yes
Host name_of_host
Hostname 192.0.2.123
User john
Host ...
Create a git repository
Create a GitLab (sign up) or a Microsoft GitHub account and a key to use for it. Go to gitlab.com or github.com to create your account - it's free for personal use.
Example: GitLab - Create your first project
After you have signed up and verification of your email is done
- Enter a Group name
- Enter a Project name
- note the URL
- Check Include a Getting Started README
Now there is some housekeeping to do. The most important is to add your public key. Recommendations: use a specific key and set a expiry date.
Example: GitHub - Start your first project
After you have signed up you can create your first project
In the Dashboard hit the [New] button to Add a New repository. You will go to Create a new repository where you enter the
- Repository name,
- it's Description for future you and guests,
- Choose Public/private,
- Check the Add a README file and
- Choose your preferred License.
- Hit the [Create repository] button
Start Using GIT
Now there is some housekeeping to do. The most important is to add your public key. But there is a lot of other stuff to go trough.
Recommendations: use a specific key and set a expiry date for it
and 2FA (Two-factor authentication) and OpenID.
Make a directory for your project mkdir /home/john/git/my-project
and cd /home/john/git/my-project
into it and configure your directory for git.
Configure Git
Clone your Repository
then clone your new GitLab project into it by git clone [email protected]:gitlab-tests/sample-project.git
. Copy the URL from Code -Clone with SSH. You may now edit any of the files or add any files to that directory.
Git Commands
cd existing_repo
git remote add origin https://gitlab.com/<user>/<repository>.git
git branch -M main
git push -uf origin main
git status
dit diff
- git status -> to tell us what we are doing
- git add <file> -> to update what will be committed
- git restore <file> -> to discard changes in working directory
- git commit -a -> to automatically stage modified and deleted files
- git commit -m "A description of what and why" -> the commit message
- git push -u origin main -> wrights it to the repository
- git pull -> get new data from the repository
Other tools
You need a terminal based editor neovim, vim or nano. Visual Studio Code link is a GUI based system that is preferred by many, also check out the truly free and open source versions. See this link about git gui.
Notes
Usage of ssh-keygen flags
ssh-keygen [-q] [-a rounds] [-b bits] [-C comment] [-f output_keyfile]
[-m format] [-N new_passphrase] [-O option]
[-t dsa | ecdsa | ecdsa-sk | ed25519 | ed25519-sk | rsa]
[-w provider] [-Z cipher]
ssh-keygen -p [-a rounds] [-f keyfile] [-m format] [-N new_passphrase]
[-P old_passphrase] [-Z cipher]
ssh-keygen -i [-f input_keyfile] [-m key_format]
ssh-keygen -e [-f input_keyfile] [-m key_format]
ssh-keygen -y [-f input_keyfile]
ssh-keygen -c [-a rounds] [-C comment] [-f keyfile] [-P passphrase]
ssh-keygen -l [-v] [-E fingerprint_hash] [-f input_keyfile]
ssh-keygen -B [-f input_keyfile]
ssh-keygen -D pkcs11
ssh-keygen -F hostname [-lv] [-f known_hosts_file]
ssh-keygen -H [-f known_hosts_file]
ssh-keygen -K [-a rounds] [-w provider]
ssh-keygen -R hostname [-f known_hosts_file]
ssh-keygen -r hostname [-g] [-f input_keyfile]
ssh-keygen -M generate [-O option] output_file
ssh-keygen -M screen [-f input_file] [-O option] output_file
ssh-keygen -I certificate_identity -s ca_key [-hU] [-D pkcs11_provider]
[-n principals] [-O option] [-V validity_interval]
[-z serial_number] file ...
ssh-keygen -L [-f input_keyfile]
ssh-keygen -A [-a rounds] [-f prefix_path]
ssh-keygen -k -f krl_file [-u] [-s ca_public] [-z version_number]
file ...
ssh-keygen -Q [-l] -f krl_file [file ...]
ssh-keygen -Y find-principals -s signature_file -f allowed_signers_file
ssh-keygen -Y match-principals -I signer_identity -f allowed_signers_file
ssh-keygen -Y check-novalidate -n namespace -s signature_file
ssh-keygen -Y sign -f key_file -n namespace file [-O option] ...
ssh-keygen -Y verify -f allowed_signers_file -I signer_identity
-n namespace -s signature_file [-r krl_file] [-O option]
References
Git Documentation [1] Git Commit [2] wikipedia [3]
GitLab AI by any LLM model [4] GitHub AI by Copilot [5]
Git Docs documentation What is Version Control?, What is Git?, Get Going with Git, Quick Wins with Git ↩︎
GitLab Get the AI-powered DevSecOps Platform homepage, why gitlab, pricing ↩︎
GitHub Let’s build from here homepage, pricing. The AI part GitHub Copilot from $10/month ↩︎