Skip to main content

Command Palette

Search for a command to run...

Git and GitHub: A Beginner-Friendly Technical Guide

Updated
•5 min read•View as Markdown
Git and GitHub: A Beginner-Friendly Technical Guide

Version control is an essential skill for modern developers. Whether you're building a personal project, contributing to open source, or working with a team, Git and GitHub help you track changes, collaborate efficiently, and maintain a reliable project history.

In this guide, we’ll walk through the fundamentals of Git and GitHub, including how to install Git, create repositories, make commits, and push your code to GitHub.

What is Git?

Git is a distributed version control system (VCS) that allows developers to track changes in their code over time. It lets you:

  • Record the history of a project

  • Work on different features using branches

  • Collaborate with other developers

  • Revert to previous versions if something breaks

Git works locally on your computer and doesn't require an internet connection for most operations.


What is GitHub?

GitHub is a cloud-based platform that hosts Git repositories. It allows developers to:

  • Store code online

  • Collaborate with teams

  • Review code through pull requests

  • Manage issues and project boards

  • Contribute to open-source projects

Think of Git as the tool and GitHub as the platform where Git repositories are stored and shared.


Installing Git

Before using Git, you need to install it on your system.

Windows

  1. Download Git from:
    https://git-scm.com/downloads

  2. Run the installer and keep the default settings.

  3. Verify installation:

git --version

macOS

Using Homebrew:

brew install git

Or download it directly from the Git website.

Linux (Ubuntu/Debian)

sudo apt update
sudo apt install git

Check installation:

git --version

Initial Git Configuration

After installing Git, configure your username and email. These are used in your commit history.

git config --global user.name "Your Name"
git config --global user.email "your@email.com"

Verify configuration:

git config --list

Creating Your First Git Repository

A repository (repo) is a folder where Git tracks changes.

Step 1: Create a Project Folder

mkdir my-first-project
cd my-first-project

Step 2: Initialize Git

git init

This creates a hidden .git directory that Git uses to track changes.

Check repository status:

git status

Adding Files to Git

Create a file:

touch index.html

Git will detect the file as untracked.

Add it to the staging area:

git add index.html

Add all files:

git add .

Check status again:

git status

Making Your First Commit

A commit is a snapshot of your project at a specific point in time.

git commit -m "Initial commit"

Best practices for commit messages:

  • Keep them short and clear

  • Use present tense

  • Explain why if necessary

Example:

git commit -m "Add homepage layout"

Creating a Repository on GitHub

  1. Go to https://github.com

  2. Click New Repository

  3. Enter a repository name

  4. Choose Public or Private

  5. Click Create Repository

GitHub will show commands to connect your local project.

Connecting Local Git to GitHub

Add the remote repository:

git remote add origin https://github.com/username/repository.git

Verify remote:

git remote -v

Pushing Code to GitHub

Push your code to GitHub:

git push -u origin main

Explanation:

  • push uploads code

  • origin is the remote name

  • main is the branch name

  • -u sets upstream tracking

After this, you can simply run:

git push

Pulling Changes from GitHub

If collaborators update the repository, pull their changes.

git pull origin main

This command fetches and merges changes from GitHub into your local repository.


Cloning an Existing Repository

To copy a repository from GitHub to your local machine:

git clone https://github.com/username/repository.git

Move into the project directory:

cd repository

Working with Branches

Branches allow you to develop features without affecting the main codebase.

Create a branch:

git branch feature-login

Switch to the branch:

git checkout feature-login

Or create and switch in one command:

git checkout -b feature-login

Merge the branch:

git checkout main
git merge feature-login

Common Git Workflow

A typical developer workflow looks like this:

Edit files
↓
git add .
↓
git commit -m "Describe changes"
↓
git push

For team collaboration:

git pull
↓
make changes
↓
git add .
↓
git commit
↓
git push

Useful Git Commands

Command Description
git status Check repository state
git log View commit history
git diff See file changes
git branch List branches
git checkout Switch branches
git merge Merge branches
git pull Fetch and merge changes
git push Upload changes

Best Practices for Using Git

Write meaningful commit messages

Bad:

update code

Good:

Fix login authentication bug

Commit often

Small commits make debugging easier.

Use branches for features

Avoid working directly on main.

Pull before pushing

Always pull the latest changes to avoid conflicts.


Final Thoughts

Git and GitHub are foundational tools for modern software development. Learning them early will significantly improve your workflow, collaboration skills, and project management.

To recap, you learned how to:

  • Install and configure Git

  • Initialize a repository

  • Add and commit files

  • Connect to GitHub

  • Push and pull code

  • Work with branches

Mastering these basics will prepare you for more advanced concepts such as pull requests, rebasing, CI/CD integration, and open-source collaboration.

Happy coding and version controlling!