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…
- Set up your user information
git config --global user.name "Your Name" git config --global user.email "your-email@example.com"
-
Verify your configuration
git config --global --list
Note: You should see something like…
user.name=Your Name user.email=your-email@example.com
- 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
- Create a new repo
git init --initial-branch=main
-
Write a simple “Hello World” program
#include <iostream> int main() { std::cout << "Hello World!" << std::endl; return 0; }
-
Compile it
g++ hello.cpp
-
Make sure it runs
./a.out
Then see what has changed in the repo with this command
git status
-
Now stage the source code
git add hello.cpp
-
Commit the changes
# -m adds a commit message, make sure it is informative! git commit -m "Initial Commit"
-
Create a git ignore file
echo "a.out" > .gitignore
-
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.