Installation and Environment Setup

Embarking on your first GitHub project involves a few foundational steps. Begin by installing Git, the distributed version control system that powers GitHub. Download the Git Bash installer from the official Git website and follow the on-screen instructions for installation. This provides a command-line interface for Git on Windows, along with essential Unix-like tools.

Concurrently, create your GitHub account. Navigate to GitHub.com and sign up. This account will serve as your remote repository host, where your project's code will live and be accessible to others.

Once Git is installed, configure your identity within Git Bash. This is crucial for Git to track who makes which changes. Run the following commands, replacing the placeholders with your actual name and email address associated with your GitHub account:

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

The --global flag ensures these settings apply to all your Git projects on this machine. These commands write your configuration to the global Git configuration file.

SSH Key Setup for Secure Authentication

To push your local code to GitHub without needing to enter your username and password every time, you'll set up an SSH key. SSH (Secure Shell) provides a more secure and convenient method for authentication. You'll generate a pair of keys: a private key (which you keep secret on your local machine) and a public key (which you'll upload to GitHub).

Generate your SSH key pair using the following command in Git Bash. It's recommended to use the Ed25519 algorithm, which is more secure and efficient than older algorithms like RSA:

ssh-keygen -t ed25519 -C "your.email@example.com"

Press Enter to accept the default file location (usually ~/.ssh/id_ed25519) and then enter a strong passphrase when prompted. This passphrase adds an extra layer of security to your private key. If prompted to overwrite an existing file, carefully consider if you intend to replace your current SSH key.

After generation, you need to add your SSH private key to the SSH agent. This allows you to use the key without re-entering your passphrase repeatedly. First, start the SSH agent in the background:

eval "$(ssh-agent -s)"

Then, add your private key to the agent:

ssh-add ~/.ssh/id_ed25519

Now, you need to copy your public SSH key. This is the key you will provide to GitHub. Display your public key in the terminal:

cat ~/.ssh/id_ed25519.pub

Copy the entire output, which starts with ssh-ed25519 and ends with your email address. Go to your GitHub account settings, navigate to "SSH and GPG keys," and click "New SSH key." Paste your copied public key into the "Key" field and give it a descriptive title (e.g., "My Work Laptop").

To verify that your SSH connection is working correctly, run this command:

ssh -T git@github.com

You should see a message confirming that you have successfully authenticated, but GitHub does not provide interactive shell access. If you see a message like "Hi username! You've successfully authenticated, but GitHub does not provide shell access," your SSH setup is complete.

Git Bash terminal displaying the output of ssh-keygen command

Creating a Local Repository

With Git and SSH configured, you can now start managing your project locally. Navigate to your project's root directory in Git Bash. If your project doesn't exist yet, create a new folder for it.

Initialize Git in your project directory. This command creates a hidden .git sub-directory that contains all the necessary Git metadata for your project:

cd /path/to/your/project
git init

After initializing, add your project files to the staging area. The staging area is an intermediate step where you prepare files for your next commit. Use the following command to add all files in the current directory:

git add .

The period (.) signifies adding all files and directories within the current path. You can also add specific files using git add filename.ext.

Commit the staged changes to your local repository. A commit is a snapshot of your project at a specific point in time. Each commit should have a clear, concise message describing the changes made:

git commit -m "Initial commit: Project setup"

The -m flag allows you to provide the commit message directly on the command line.

Connecting to a Remote GitHub Repository

Now, you need to create a corresponding repository on GitHub to host your project remotely. Go to GitHub, click the '+' icon in the top-right corner, and select "New repository." Give your repository a name (it's common practice to name it the same as your local project folder), add a description, and choose whether to make it public or private. You can also choose to initialize it with a README file, a .gitignore file, or a license, but for this guide, we'll assume an empty repository.

Once the repository is created, GitHub will provide you with a URL. This URL is the remote address for your repository. You'll typically see two options: HTTPS and SSH. Since you've set up SSH, use the SSH URL, which will look something like git@github.com:your-username/your-repository-name.git.

Add this remote repository to your local Git configuration. You'll name this remote origin, which is the conventional name for the primary remote repository:

git remote add origin git@github.com:your-username/your-repository-name.git

Verify that the remote has been added correctly by listing your remotes:

git remote -v

This should display the fetch and push URLs for your origin remote, confirming it points to your GitHub repository.

Pushing Your Local Project to GitHub

The final step is to push your local commits to the remote repository on GitHub. This synchronizes your local project with the one hosted on GitHub.

Use the git push command. You'll specify the remote name (origin) and the branch name you want to push to. Typically, the main branch is called main (or master on older repositories). If you're unsure, you can check your current branch with git branch.

To push your local main branch to the origin remote, use:

git push -u origin main

The -u flag (short for --set-upstream) links your local branch to the remote branch. This means that in the future, you can simply use git push from your local main branch, and it will automatically push to origin/main. If your default branch is named master, replace main with master.

After running this command, your local project files will be uploaded to your GitHub repository. Refresh your GitHub repository page, and you should see all your committed files. You have successfully deployed your first project from a local folder to GitHub using Git and SSH.