git CLI

First, familiarize yourself with what git is and what it is used for.

This is a guide for the git CLI. CLI stands for Command Line Interface. A CLI is typically called within a terminal. If you don't know what a terminal is, I have no idea why we are even working together.

Before doing anything else in this guide, make sure you have git installed. Type git in any console window. If you've properly installed git, it should print some helpful information for the git command. If not, get it from here.

Cloning a repository

To clone a repository, simply enter the following command:

git clone <url>

An example use would be:

git clone https://gitlab.com/illateral_software/scribes.git

If you've set up your git credentials properly, it will just work, if not, git will prompt you for your credentials. Credentials are only needed for private repositories.

The line of code you see above is an example of cloning with HTTPS. Ideally (especially if you have enabled 2FA, which I strongly recommend), you'd want to clone with SSH, which would look like this:

git clone git@gitlab.com:illateral_software/scribes.git

For guides on how to enable 2FA or use SSH, please see the official GitLab documentation.

When cloning a repository, remember that a new folder is created that is named after the repository. This folder will contain the repository files.

Pulling a repository

Pulling means getting new data from the repository. Pulling usually happens on the branch that you're currently on. Typically, you can never pull enough times. Pulling before doing any sort of work is a great preventative method for avoiding merge conflicts and physical conflicts with me.

To pull, simply write:

git pull

This will pull all the latest changes into your local version of the repository.

Commits

Commits are really cool and you should use them all the time. When you've done some work and want to 'save' what you've changed, you first stage the files you wish to put into the commit. You do this by writing:

git add <path to file>

For example:

git add index.html

This will stage index.html. Staged files will be put into the next commit. Once you've staged everything you want in your commit, type:

git commit -m "message"

Make sure to provide a meaningful message that describes what you've done in your commit. Sometimes, you or others will need to revert to a specific commit, and your messages will be used to determine which commit makes sense.

Pushing

Pushing means putting your code on GitLab. To push, simply type:

git push

Sometimes, git screams something incomprehensible at you, but most of the time, the gibberish contains useful commands. Otherwise, everything is quite googleable.

Branching

Branches are a useful way to separate your stuff when working on different things. Branches can be created from existing branches. To branch from master / main for example, checkout the master branch and use the following command:

git checkout -b <branch name>

This will create a new branch from the master branch and immediately put you on this new branch.

To checkout different branches, use the command

git checkout <branch name>

Keep in mind that you will always commit, pull and push on the branch you are currently on. When checking out different branches, your local repository changes to reflect the branch you have chosen.

Merge Requests

When you've pretty much completed a feature and you think it is ready to go into the master branch, create a merge request in GitLab. You can do this in the GitLab menu. A typical link would be https://gitlab.com/illateral_software/scribes/-/merge_requests. Make sure to replace 'scribes' with the designated repository name (or just do it with the GUI like a normal person).

You may assign me as reviewer of the merge request. In most cases, I get notified anyway.

Thank you for readings this guide. A vscode git guide will follow sometime.