Getting started with Git and GitLab
I'm using Git to take a series of snapshots of my program files - stored in a project directory configured as a git repository - as things change over time. Git allows me to add or roll back any of those changes as desired. GitLab, then, provides a free service for web-hosting git repositories that can be configured for public or private access.
Let's go!
Install git
on a Debian/Ubuntu-based Linux system by running ...
$ sudo apt install git
$ git --version
git version 2.25.1
Configure a username and email address. Every time git commit ...
takes a snapshot it adds this information to the commit ...
$ git config --global user.name "MY USERNAME"
$ git config --global user.email "MY EMAIL ADDRESS"
$ git config --global --list
Settings are stored in ~/.gitconfig
.
Local git repository
This month I'm exploring a bit of Python programming and I created a new project called bootsound. I track my changes by making my project directory into a git repository ...
$ cd bootsound
$ git init
... which creates a new .git
directory.
I start by creating 3 placeholder files that commonly exist in project directories tracked by git
:
.gitignore
- just as it says, git will ignore changes to any files listed hereLICENSE.md
- license used for the code (GPLv3 in my case) formatted in MarkdownREADME.md
- project description
Create, add, and commit the changes ...
$ touch .gitignore LICENSE.md README.md
$ git add .
$ git commit -m 'first commit'
$ git log
SSH keys
I use SSH to move data between local and (soon to be hosted on GitLab) git repositories. I configure no-password-at-login authentication to the remote repository by using SSH keys.
Check for existing keys ...
$ ls -al ~/.ssh/*pub
Generate new keys and assign a key passphrase ...
$ ssh-keygen -t ed25519 -C "$(whoami)@$(hostname)-$(date -I)"
Restrict access to ~/.ssh
...
$ chmod 700 ~/.ssh
See also: Secure remote access using SSH keys
GitLab account
Free sign-up. Just setup the user - step 1 - for now. Groups and git projects can be created as desired.
Add the public *.pub
SSH key to the newly-created account. On the GitLab namespace page, click on the avatar in the upper-right corner and select Settings->SSH Keys. Copy/paste the string of characters in the public SSH keyfile and click Add key.
Test ...
$ ssh -T git@gitlab.com
[...]
Welcome to GitLab, @YOUR_USERNAME!
GitLab project
Click the plus icon in the navigation bar and select New Project
and Create blank project
. Add details and click to create.
Now I can push (transfer) the contents of my existing bootsound
local folder to the remote GitLab repository ...
$ cd bootsound
$ git remote add origin git@gitlab.com:dwarmstrong/bootsound.git
$ git remote -v
origin git@gitlab.com:dwarmstrong/bootsound.git (fetch)
origin git@gitlab.com:dwarmstrong/bootsound.git (push)
$ git push -u origin master
Good to go! GitLab basics guides and the Pro Git book are helpful resources to learn more.
» Later: Nostromo boot noise
« Earlier: Now not later