Git_Tutorial

Description of 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:

        
            # install git via winget on windows
            winget install --id Git.Git -e --source winget
            
            # install git via homebrew on mac
            brew install git

            # install git via macport on mac
            sudo port 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:

Description of 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

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. Go to Git server (e.g., GitHub, Bitbucket) and find the section where I can add SSH keys (usually in the account settings).

  1. Copy the contents of the public SSH key file.
  2. Paste the key in the SSH key section of the Git server.
  3. Enter a label for the key, e.g. My Laptop.
  4. Click Add SSH key to add the key to the Git server.
Description of Image

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

Description of Image Description of Image

4. 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
            
        

5. Basic Git Commands

Here are some basic Git commands I'll use:

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