Git Setup & Your First Repo
It’s time to stop reading and start doing! In this guide, we will transform your computer into a developer workstation.
Step 1: Install Git
First, we need to get the Git engine running on your machine.
- 🪟 Windows
- 🍎 macOS
- 🐧 Linux
- Download the Git for Windows installer.
- Run the
.exefile. - Important: When asked about the "Default Editor," you can choose Visual Studio Code.
- Keep all other settings as "Default" and click Install.
- Open your Terminal (Command + Space, type
Terminal). - Type
git --versionand hit Enter. - If you don't have it, a popup will ask you to install Xcode Command Line Tools. Click Install.
- Alternatively, if you use Homebrew, run:
brew install git.
Open your terminal and run the command for your distribution:
- Ubuntu/Debian:
sudo apt install git-all - Fedora:
sudo dnf install git-all
Step 2: Configure Your Identity
Git needs to know who is making changes. Open your terminal (or Git Bash on Windows) and type these two lines:
git config --global user.name "Your Name"
git config --global user.email "your-email@example.com"
Note: Use the same email address you plan to use for your GitHub account.
Step 3: Create Your First Repository
Let's create a "Hello World" project and track it with Git.
1. Create a Folder
mkdir my-first-repo
cd my-first-repo
2. Initialize Git
This creates a hidden .git folder. This is where the "Time Machine" lives!
git init
3. Create a File
Create a simple file named hello.txt and add some text to it.
4. The Magic Sequence (Add & Commit)
# Add the file to the Staging Area
git add hello.txt
# Save the snapshot to the Local Repository
git commit -m "feat: my very first commit"
Step 4: Connect to GitHub
Now, let's put your code in the cloud so the world can see it.
- Go to GitHub.com and create a free account.
- Click the + icon in the top right and select New Repository.
- Name it
my-first-repoand click Create repository. - GitHub will give you a "Remote URL" (it looks like
https://github.com/your-username/my-first-repo.git).
Run these commands in your terminal to link your computer to GitHub:
# Link your local repo to the cloud
git remote add origin https://github.com/your-username/my-first-repo.git
# Rename your main branch to 'main' (standard practice)
git branch -M main
# Upload your code!
git push -u origin main
How to Check Your Work
Refresh your GitHub repository page. You should see your hello.txt file sitting there!
Common Commands Cheat Sheet
| Command | Purpose |
|---|---|
git status | See which files are modified or staged. |
git log | See the history of all your commits. |
git diff | See exactly what lines changed in your files. |
git branch | List your current branches. |
You are now officially using Version Control. You have a local history on your computer and a backup in the cloud. You are ready to start building real backend applications!