Git for GitHub: How to use simple Git commands to manage a GitHub repository

Published: (May 28, 2026 at 05:18 PM EDT)
7 min read
Source: Dev.to

Source: Dev.to

The Story

Recently, I was working on creating a website on a cloud‑based IDE (CodeHS). One night I finished editing, turned off my monitor, and disabled my mouse and keyboard. The next day at school I continued working and made significant changes. When I got home and made more changes, I realized something very important: the cloud‑based IDE hadn’t refreshed to the new code, so when I saved my new work it overwrote the work I did at school.

What’s the point of telling you this? It isn’t “always close your editor” or some other trick. After the initial panic I discovered the IDE’s History section, which logs every change to every file. I copied the lost changes from the history and restored them.

Now imagine you aren’t using a cloud‑based IDE—just editing a file locally in an IDE or the terminal. When something breaks, the previous states of your files can be lost forever.

Using a version control system (VCS) like Git prevents that: you can always go back to previous commits (snapshots of your code).

The work I almost lost wasn’t critical, but imagine losing important code for a job or a serious project.


What Is Git?

Git is the most popular VCS in the world. It’s free, open‑source, and actively maintained.

“By far, the most widely used modern version control system in the world today is Git. Git is a mature, actively maintained open source project originally developed in 2005 by Linus Torvalds, the famous creator of the Linux operating system kernel.”
Atlassian

In this guide you will learn how to:

  1. Install Git.
  2. Configure your identity.
  3. Initialize a local repository.
  4. Commit and push changes to a GitHub repository.

Step 1 – Install Git

Open a terminal

OSHow to open
WindowsPress Windows Key, type PowerShell, and press Enter.
macOSPress ⌘ Space, type Terminal, and press Enter.
LinuxPress Ctrl + Alt + T.

Verify the installation

git --version

If a version number appears, you’re ready for Step 2.
If the command is not recognized, follow the OS‑specific instructions below.

Windows

  • Via Winget

    winget install --id Git.Git -e --source winget
  • Via installer – download the standalone installer from the official site:

macOS

  • Via Homebrew (install Homebrew first if you don’t have it)

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    brew install git

Linux

Use your distribution’s package manager:

DistributionCommand
Debian/Ubuntusudo apt-get install git
Fedorasudo dnf install git
Archsudo pacman -S git

Step 2 – Configure Your Identity

Git attaches a name and email to every commit. Set them globally:

# Your display name (real name, GitHub username, etc.)
git config --global user.name "Your Name"

# Your email (must match the email on your GitHub account)
git config --global user.email "your-email@example.com"

You can verify the settings with:

git config --global --list

Step 3 – Initialize a Local Repository

  1. Navigate to the folder where you want the project:

    cd path/to/your/project
  2. Create the repository and set the default branch to main:

    git init -b main
  3. Stage all files (tell Git to start tracking them):

    git add .
  4. Commit the staged files with a clear, imperative‑mood message:

    git commit -m "Initial commit"

    Example of good commit style: Add CSS rule to fix whitespace (not “Added CSS rule …”).


  1. Create a GitHub account if you don’t already have one.
  2. Sign in at .
  3. Click the green “New” button (top‑right of the Repositories list) or go directly to .
  4. Fill in a repository name.
  5. Leave all “Add …” boxes unchecked (no README, .gitignore, or license for now).
  6. Click Create repository.

Add the remote and push your local commit

# Replace USER and REPO with your GitHub username and repository name
git remote add origin https://github.com/USER/REPO.git

# Push the local main branch to GitHub
git push -u origin main

You should now see your code on GitHub.


Recap

  • Never rely on a single copy of your work.
  • Git gives you a complete history of every change, letting you recover lost work instantly.
  • Follow the steps above to install Git, configure it, initialize a repository, and push to GitHub.

Happy coding! 🚀

Create Repository

  1. Click Create Repository.
  2. Remember the URL for your repository – you’ll need it in the next step.

Navigate to your local project folder and run the command below, replacing “ with the URL you saved in step 2.

git remote add origin 

Pushing to GitHub

Now push your local commits to the remote repository:

git push -u origin main
  • The -u flag sets upstream tracking, linking your local main branch to the remote origin/main. Future pushes can be done with just git push.

You have now:

  • Initialized a local Git repository
  • Tracked your changes
  • Pushed the code securely to GitHub

Your workflow is much simpler now that the local project is linked to a remote repository.


Typical Git Workflow (Four Core Commands)

CommandWhat It Shows / Does
git status• Current branch
• How many commits you’re ahead/behind the remote
• Unstaged changes
• Untracked files
git add (or git add .)Stage files (tell Git to track them)
git commit -m "COMMIT MESSAGE"Save a snapshot locally (still only on your machine)
git pushSend committed changes to the remote repository

Tip: Run git status before you start working to see the current state of your repository.

If you ever need to be explicit about the remote and branch, you can use:

git push origin main

Adding a .gitignore File

A .gitignore file tells Git which files not to track. Place it in the root of your project and add one rule per line.

Common Syntax

  • # – comment line
  • secret.txt – ignore this exact file
  • private/ – ignore the directory and everything inside it
  • *.txt – ignore all files ending with .txt
  • log* – ignore any file that starts with log
  • **/logs – ignore any directory named logs at any depth
  • !important.txt – re‑include a file that was previously ignored
  • /config.yaml – pattern anchored to the location of the .gitignore file (not the filesystem root)

Why Version Control Matters

Imagine you’re developing an Automated Market‑Making (AMM) system that places buy and sell orders across many stocks. A bug in the code could cause costly errors for the company.

  • Without a VCS: Downtime and financial loss could be severe because you can’t easily revert to a known‑good state.
  • With Git: You can roll back to a previous commit, fix the issue, and redeploy quickly, saving time and money.

Version control also enables:

  • Collaboration: Multiple developers can work on the same codebase simultaneously.
  • Code Review: Changes can be reviewed and approved before merging.

Even for solo projects, not using a VCS can lead to lost progress and frustration.


Writing Good Commit Messages

A clear commit history is essential. While you’re still improving your commit messages, consider adopting the Conventional Commits standard. It provides a structured format that makes logs easier to read and automate.

I won’t detail the standard here, but you can read a concise summary here.

0 views
Back to Blog

Related posts

Read more »

FiXiY - Find X in Y

TRIESTE, Italy – For developers, system administrators, and digital hoarders alike, the daily struggle of locating a specific snippet of text buried deep inside...