What You Need to Start with Git

Author: FERKIOUI Akram
TechCourse
Created: Oct 20, 2025
Updated: Oct 21, 2025
10 min read
0 views

A beginner-friendly introduction to the essential Git commands and concepts. This course will equip you with the fundamental skills to start versioning your projects and collaborating with other developers effectively.

Introduction to Git

Git is a distributed version control system. Think of it as a way to save snapshots (called "commits") of your project over time. This allows you to track changes, revert to previous versions, and collaborate with others without overwriting each other's work.

1. Initializing a Repository

First, you need to tell Git to start tracking a project.

2. The Basic Workflow: Status, Add, Commit

This is the core cycle you'll use constantly.

Example: Let's say we have a folder with 3 files

code.bash
1git init 2# Output: Initialized empty Git repository in [path]/.git/ 3 4git status 5# Output: 6# On branch main 7# No commits yet 8# Untracked files: 9# (use "git add <file>..." to include in what will be committed) 10# index.html 11# styles.css 12# script.js 13# nothing added to commit but untracked files present 14 15git add index.html styles.css script.js 16# No output 17# Or you can basically use "git add ." to add all files 18 19git status 20# Output: 21# On branch main 22# No commits yet 23# Changes to be committed: 24# (use "git rm --cached <file>..." to unstage) 25# new file: index.html 26# new file: styles.css 27# new file: script.js 28 29git commit -m "Initial commit: add basic website structure" 30# Output: [main (root-commit) abc1234] Initial commit: add basic website structure 31# 3 files changed, 15 insertions(+) 32# create mode 100644 index.html 33# create mode 100644 styles.css 34# create mode 100644 script.js

3. Working with a Remote Repository (like GitHub)

To collaborate or to have an online backup of your code, you'll use a remote repository.

Example:

Let's stay on the same project

First, set up a remote repository and push:

code.bash
1# Add a remote repository (like GitHub, GitLab, etc.) 2git remote add origin https://github.com/yourusername/your-repo.git 3 4git push -u origin main 5# Output: 6# Enumerating objects: 3, done. 7# Counting objects: 100% (3/3), done. 8# Writing objects: 100% (3/3), 256 bytes | 256.00 KiB/s, done. 9# Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 10# To https://github.com/yourusername/your-repo.git 11# * [new branch] main -> main 12# Branch 'main' set up to track remote branch 'main' from 'origin'

Later, when you want to pull changes:

code.bash
1git pull origin main 2# Output: 3# remote: Enumerating objects: 1, done. 4# remote: Counting objects: 100% (1/1), done. 5# remote: Total 1 (delta 0), reused 0 (delta 0), pack-reused 0 6# Unpacking objects: 100% (1/1), 652 bytes | 652.00 KiB/s, done. 7# From https://github.com/yourusername/your-repo 8# * branch main -> FETCH_HEAD 9# abc1234..def5678 main -> origin/main 10# Updating abc1234..def5678 11# Fast-forward 12# README.md | 1 + 13# 1 file changed, 1 insertion(+) 14# create mode 100644 README.md

After making local changes and pushing again:

code.bash
1git push 2# Output: 3# Enumerating objects: 5, done. 4# Counting objects: 100% (5/5), done. 5# Writing objects: 100% (3/3), 312 bytes | 312.00 KiB/s, done. 6# Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 7# To https://github.com/yourusername/your-repo.git 8# def5678..ghi9012 main -> main

Git Push/Pull workflow diagram

4. Branching and Merging: Working in Parallel

Branches are a fundamental concept in Git. They allow you to work on different features or bug fixes in isolation without affecting the main codebase.

Once you've finished your work on a branch and are ready to integrate it back into the main codebase (often the main or master branch):

Example:

code.bash
1# Create and work on a new feature branch 2git branch feature-new-header 3# (No output if successful) 4 5git checkout feature-new-header 6# Output: Switched to branch 'feature-new-header' 7 8# Or use: git checkout -b feature-new-header (creates and switches in one command) 9 10# Make changes to files, then add and commit 11git add index.html 12git commit -m "Add new header section" 13# Output: [feature-new-header def5678] Add new header section 14# 1 file changed, 5 insertions(+) 15 16# Switch back to main branch 17git checkout main 18# Output: Switched to branch 'main' 19 20# Merge the feature branch into main 21git merge feature-new-header 22# Output: Updating abc1234..def5678 23# Fast-forward 24# index.html | 5 +++++ 25# 1 file changed, 5 insertions(+) 26 27# Check the log to see the merge 28git log --oneline 29# Output: 30# def5678 Add new header section 31# abc1234 Initial commit: add basic website structure 32 33# Delete the feature branch 34git branch -d feature-new-header 35# Output: Deleted branch feature-new-header (was def5678)

Git Branches workflow diagram

5. Pull Requests: Proposing Changes

When working in a team, instead of merging directly, you'll often use a "Pull Request" (PR) on platforms like GitHub or GitLab.

  1. Push your branch: After committing your changes to your feature branch, you push it to the remote repository: git push origin <branch-name>.
  2. Open a Pull Request: Go to the repository on GitHub. You will usually see a prompt to create a Pull Request from your recently pushed branch.
  3. Review and Merge: A Pull Request is a formal proposal to merge your changes. It allows your teammates to review your code, leave comments, and suggest changes before it's merged into the main branch. Once approved, the changes can be merged.

Git Pull Requests workflow diagram

6. Ignoring Files: .gitignore

Often, there are files or entire directories in your project that you do not want to track with Git. These can include:

Dependencies managed by package managers (e.g., a node_modules folder).

Build artifacts or compiled code (e.g., /dist, *.exe).

Log files (*.log).

Files containing sensitive information like API keys or credentials (e.g., .env files).

Operating system-specific files (e.g., .DS_Store on macOS).

To prevent Git from tracking these files, you create a special file in the root directory of your project named .gitignore.

Each line in this file lists a pattern for a file or folder that Git should ignore. These ignored files won't show up in git status and cannot be added to a commit.

Example:

code.txt
1# Ignore dependency folders 2node_modules/ 3vendor/ 4 5# Ignore log files 6*.log 7 8# Ignore environment variables file 9.env 10 11# Ignore build output directory 12/dist

Was this article helpful?

Let us know what you think! Your feedback helps us improve.