How to Use Git Locally and Sync with GitHub: A Beginner’s Guide

Whether you’re an earth scientist or a student, learning how to use Git on your local machine can significantly enhance how you manage your projects. For those of you, who don’t know what is Github, I would strongly recommend reading this blog for 2 minutes. Git ensures that you never lose your code and makes collaborating on projects easier. This guide will explain why Git is crucial for safeguarding your work and provide a step-by-step process for pushing your local code to GitHub.

Why Use Git and GitHub?

Using Git locally allows you to track every modification to your code, step by step. You can revert to previous versions at any time, compare changes, or even explore different development paths via branches. Once your local repository is linked to GitHub, your code is backed up on the cloud, making it accessible from anywhere and safe from local hardware failures.

Step-by-Step Guide to Using Git Locally and Pushing to GitHub

Step 1: Install Git

  1. Download and install Git from git-scm.com.
  2. Open your terminal (Command Prompt on Windows, Terminal on macOS and Linux).
  3. Configure your Git username and email using these commands:


Step 2: Initialize Your Local Repository

  1. Navigate to the folder where your project is located (or where you want to create a new project):
  2. Initialize a new Git repository:

Step 3: Add Project Files to Your Repository

  1. Add files to the staging area using:Note: The . adds all files in the directory. You can specify individual files instead.
  2. Commit your files to the repository:

Step 4: Connect Your Local Repository to GitHub

  1. Create a new repository on your GitHub account (do not initialize it with a README, .gitignore, or License).
  2. Copy the repository URL provided by GitHub.
  3. Link your local repository with the remote repository using
  4. Verify the new remote URL:

Step 5: Push Your Code to GitHub

  1. Push your local commits to GitHub:
  2. Enter your GitHub credentials if prompted.

Congratulations! You’ve just learned how to manage your project with Git locally and push your repository to GitHub. This setup not only safeguards your work against loss but also makes it easier to collaborate with colleagues or the public. Remember, the more you use Git, the more intuitive it will become. If you have any trouble, just comment below; I will be happy to answer.

 

3 thoughts on “How to Use Git Locally and Sync with GitHub: A Beginner’s Guide

  1. Your blog is a breath of fresh air in the often stagnant world of online content. Your thoughtful analysis and insightful commentary never fail to leave a lasting impression. Thank you for sharing your wisdom with us.

Leave a Reply

Your email address will not be published. Required fields are marked *