
What is Git?
Git is a free, open-source version control system that helps you track changes in your code over time. Think of it as a powerful undo button for your projects whether you’re working alone or collaborating with others. It lets you save snapshots of your work, switch between versions, and collaborate without overwriting each other’s code. Git is fast, flexible, and has become the industry standard for managing code especially when paired with platforms like GitHub or GitLab.
Installation
If you’re on Fedora (or any closely-related RPM-based distribution, such as RHEL or CentOS), you can use dnf:
sudo dnf install git-all
If you’re on a Debian-based distribution, such as Ubuntu, try apt:
apt update && apt install git -y
We can download Git for windows from here. For more details on installation please visit this guide from git.
Once installed we can verify the installation in our terminal with:
git --version
Configuring Git
Once Git is installed, it's important to configure your identity so that your commits are properly attributed. This information is stored in your Git configuration file and will be used in every repository you work with.
Start by setting your name and email address:
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
The --global flag ensures that these settings apply to all repositories on your system. If you want to override these details for a specific project later, you can re-run the same commands without --global from within that repository.
git config --list
This will display your Git setup, including user information, editor, and other useful defaults.
Setting Up SSH Keys
To securely connect your local Git setup with services like GitHub or GitLab, it’s recommended to use SSH authentication. This avoids entering your username and password every time you push or pull from a remote repository.
Step 1: Check for existing SSH keys
First, check if you already have an SSH key:
ls -al ~/.ssh
If you see files like id_rsa and id_rsa.pub, you already have a key pair.
Step 2: Generate a new SSH key
If you don’t have one, or want a fresh key for Git:
ssh-keygen -t ed25519 -C "you@example.com"
If you're using an older system that doesn’t support ed25519, use:
ssh-keygen -t rsa -b 4096 -C "you@example.com"
Just press Enter through the prompts to use the default file location and no passphrase (or set one if you prefer more security).
Step 3: Add the SSH key to your agent
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
Step 4: Adding Your SSH Key to GitHub
- Copy your public SSH key to the clipboard:
cat ~/.ssh/id_ed25519.pub

- Click “New SSH key”, give it a name (like “my-ssh-key”), and paste the key
- Click Add SSH key
Git CheatSheet
Create / Clone Repository
git init # Initialize new Git repo
git clone <url> # Clone existing repo
Working with Files
git status # Show file changes
git add <file> # Stage specific file
git add . # Stage all files
git restore <file> # Unstage or discard changes
Committing Changes
git commit -m "message" # Commit staged changes
git commit -am "message" # Stage + commit tracked files
Syncing with Remote
git remote add origin <url> # Add remote repo
git remote set-url origin git@github.com:your-username/your-repo.git # Set Origin
git push -u origin main # Push to remote (first time)
git push # Push changes
git pull # Pull latest changes
Branching
git branch # List branches
git branch <name> # Create branch
git checkout <name> # Switch branch
git switch -c <name> # Create and switch
git merge <name> # Merge branch into current
git branch -d <name> # Delete branch
Viewing History
git log # Full commit history
git log --oneline --graph # Visual history
git show <commit> # Show specific commit
Undo / Reset
git reset --soft HEAD~1 # Undo last commit (keep changes)
git reset --hard HEAD~1 # Remove commit + changes
git revert <commit> # Create revert commit
Tags
git tag # List tags
git tag <v1.0> # Create tag
git push origin <tagname> # Push tag


