Installation

Make sure you have Git installed

sudo apt install git

Verify with

git --version

You should see an output like:

git version 2.43.0

Windows

  • Download Git Installer and run it with the default settings

  • Open the git bash and verify the installation with

git --version

Mac

  • install with HomeBrew
brew install git
  • or with Xcode Command line tools
xcode-select --install

Linux

  • Ubuntu/Debian based
sudo apt update && sudo apt install git

Setup Git

Once Git is installed, you are gonna want to configure git properly…

  1. Set up your user information
    git config --global user.name "Your Name"
    git config --global user.email "your-email@example.com"
    
  2. Verify your configuration

    git config --global --list
    

    Note: You should see something like…

    user.name=Your Name
    user.email=your-email@example.com
    
  3. See the Github tab to link your profile to your git repository.
  • After connecting your account, test your connection with
    ssh -T git@github.com
    

    Note: You will see…

    Hi <your-username>! You've successfully authenticated.
    

Create a Repository

  1. Create a new repo
    git init --initial-branch=main
    
  2. Write a simple “Hello World” program

    #include <iostream>
    int main()
    {
        std::cout << "Hello World!" << std::endl;
        return 0;
    }
    
  3. Compile it

    g++ hello.cpp
    
  4. Make sure it runs

    ./a.out
    

    Then see what has changed in the repo with this command

    git status
    
  5. Now stage the source code

    git add hello.cpp
    
  6. Commit the changes

    # -m adds a commit message, make sure it is informative!
    git commit -m "Initial Commit"
    
  7. Create a git ignore file

    echo "a.out" > .gitignore
    
  8. To view the history of the repo

    git log
    

    Shows who made what changes and when

Note: you can visit the Git to see how to work with Remote repositories.