Introduction: Why Version Control Matters

Manually managing project files, often leading to confusing names like project_final_1 and project_final_2, quickly becomes unmanageable. Version control systems like Git solve this by recording a detailed history of code changes over time. GitHub, an online platform, then stores these changes remotely, offering a secure backup and a platform to showcase your work through repositories. Repositories are the core organizational unit on GitHub, replacing traditional folder structures for project storage.

Step 1: Installing Git

The first prerequisite is installing Git on your local machine. The installation process varies by operating system. Once Git is installed, you need to configure it with your identity. This is crucial because Git records who made each change. Open Git Bash (or your terminal of choice) and use the following commands to set up your global Git configuration:

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

Replace "Your Name" and "your.email@example.com" with your actual name and email address. This configuration applies to all your Git projects on this machine.

Screenshot of Git Bash terminal after running user configuration commands

Step 2: Creating a Local Git Repository

Navigate to your project's root directory in Git Bash. If you haven't created the project folder yet, create it now. Then, initialize Git within that folder using the command:

git init

This command creates a hidden .git subdirectory within your project. This directory contains all the necessary repository files—your local Git database. It doesn't export your project or copy anything; it just sets up the tracking mechanism.

Step 3: Staging and Committing Changes

After initializing Git, you can start adding files to be tracked. To add a specific file, use:

git add <file_name>

To add all new and modified files in the current directory and its subdirectories, use:

git add .

The git add command stages your changes. Staging is like preparing a snapshot of your current work. Once staged, you need to commit these changes to your local repository's history. A commit is a save point. Each commit should represent a logical unit of work. Use the following command to commit staged changes:

git commit -m "Your descriptive commit message"

The -m flag allows you to provide a commit message directly. This message should concisely describe the changes made in that commit. Good commit messages are vital for understanding the project's history later.

Step 4: Creating a GitHub Repository

Before pushing your local changes to GitHub, you need a remote repository to push them to. Log in to your GitHub account. On the GitHub homepage, click the plus (+) icon in the top-right corner and select "New repository." Give your repository a name (it's common to name it after your project), add an optional description, and choose whether to make it public or private. You can also initialize the repository with a README file, a .gitignore file, or a license, but for this guide, we'll assume you're pushing an existing local project.

GitHub 'Create a new repository' form with fields for name and description

Step 5: Connecting Local to Remote Repository

Once your GitHub repository is created, GitHub provides you with a URL for your remote repository. This URL will be in one of two formats: HTTPS or SSH. For this guide, we'll use HTTPS. Copy the HTTPS URL provided on the repository's page. Back in your Git Bash terminal, still in your project's root directory, add this remote repository using the following command:

git remote add origin <your_github_repository_https_url>

Here, origin is the conventional short name for your remote repository. You can verify that the remote has been added by running:

git remote -v

This command should display the fetch and push URLs for your origin remote.

Step 6: Pushing to GitHub

Now that your local repository is connected to your remote GitHub repository, you can push your committed changes. The command to push is:

git push -u origin main

If your default branch is named master instead of main, use git push -u origin master. The -u flag sets the upstream branch, meaning that in the future, you can simply use git push and git pull without specifying origin main. This command uploads all the commits from your local main (or master) branch to the origin remote repository on GitHub. After the push completes, refresh your GitHub repository page, and you should see your project files and commit history.

Conclusion: Your Project is Now Version Controlled

You have successfully taken a project from a local folder and uploaded it to GitHub using Git. This process establishes a robust version control workflow. You can now continue making changes locally, committing them, and pushing them to GitHub to maintain a live backup and a shareable record of your project's evolution. This fundamental skill is essential for any developer working collaboratively or managing projects of any significant size.