Skip to main content

Git_Tutorial

Git – tool for version control

image

What’s Git?

Git is a version control software that allows developers to develop the same project. It allows developers to track the changes to a set of files which is called “repository” or “repo”. Install Git.

We need to install Git:

  1. On Windows: Download installer from git-scm.com. I install git by winget tool, I type the command in command prompt shown as below:
winget install --id Git.Git -e --source winget
  1. On Mac: You can use Homebrew or MacPort to install. You can use the command as below.
  • Homebrew:
brew install git
  • Macports:
sudo port install git
  1. On Linux: You can use apt-get to install git.
apt-get install git

1. Basic Git Configuration

After installing Git, I configure my username and email as Git attaches the information to the commits:

git config --global user.name "my name"
git config --global user.email "my email"

My name can be found as below:

image

2. SSH Keys

2.1 Generating SSH Keys

SSH keys are used to establish a secure connection between my computer and the Git server. Here’s how to set them up:

  1. Open a terminal or command prompt.
  2. Enter ssh-keygen and press Enter to create a new SSH key.
  3. When prompted, provide a file path to save the key, or just press Enter to accept the default location.
  4. Enter a secure passphrase when prompted or press Enter to continue without a passphrase (which is not recommended). After generating the SSH keys, I will have a private key (id_ed25519) and a public key (usually id_ed25519.pub).

2.2 Adding SSH Key to the Git Server

  1. Locate public SSH key file and open it with a text editor to copy its contents. In my case, the file is id_ed25519.pub.
  2. Go to Git server (e.g., GitHub, Bitbucket) and find the section where I can add SSH keys (usually in the account settings).

image

  1. Paste public key into the appropriate area and save it.

image image

Cloning a Repository

To start working on an existing project. The current repository needed to be cloned:

git clone https://gitlab.fabcloud.org/academany/fabacademy/2025/labs/chaihuo/students/chonkit-kuok.git

Basic Git Commands

Here are some basic Git commands I'll use:

  • git status: Check the status of Ir files (modified, added, etc.).
  • git add .: Add all changes to the staging area.
  • git commit -m "Ir commit message": Commit Ir changes with a message.
  • git push: Push Ir changes to the remote repository.
  • git pull: Pull the latest changes from the remote repository.