Years ago, git won a popularity contest and become the standard tool for source code management and sharing. Linux distributions like Pop!_OS have it installed by default; but any Debian-based distribution can install it with apt.
sudo apt install git
You don't need more than that if you just want to clone repositories, but if you want to contribute code of your own, then some configuration helps. You can set the name and email address associated with the commits you make.
git config --global user.name "Steven Baldasty" git config --global user.email "example@bitflippin.com"
The default branch for new repositories used to be called master
, but preference has since shifted to main
. You can set the name of the default branch explicitly for repositories you create in the future during this transition period.
git config --global init.defaultBranch "main"
If git has become the standard version control tool, then GitHub has become the standard place to store source code in the cloud - although it certainly has competitors. The smoothest way I have found to interact with GitHub repositories is by using ssh keys. I like to generate separate keypairs for every service I interact with, and for every device I interact with the service from.
ssh-keygen -t ed25519 -C "sbaldasty@gmail.com" # I enter 'github_ed25519' when prompted for a name
This generates a private key ~/.ssh/github_ed25519
which you keep secret, and a public key ~/.ssh/github_ed25519.pub
which you upload to GitHub. See GitHub's guide for more information about how to upload your public key.
When you clone repositories, you may notice have a choice between the https
or git@github
option. The second lets you push changes with your key, but the first does not; I never use https
.
I like to organize the repositories I clone using a consistent directory structure. I have ~/Code/github
(because I sometimes use other services besides GitHub), and subdirectories under that for users, and subdirectories under users for repositories. I use this script for convenience.
#!/bin/bash set -e if ! [ $# -eq 2 ]; then echo "Requires 2 parameters." exit 1 fi d=$HOME/Code/github/$1 mkdir -p $d git clone git@github.com:$1/$2.git $d/$2
I named the script ghclone.sh
and keep it in ~/bin
. To clone my Hunt the Wumpus applet for instance, I can run this from anywhere.
ghclone.sh sbaldasty wumpus-applet
The script currently does not supply any help or clean up any files or directories it created if cloning the repository fails.