The Developer's Git & GitHub Guide: From Command Line to Collaboration

If you've ever renamed a file final_v2_FINAL_reallyfinal.js because you were too scared to overwrite your last working version, this guide is for you. Git solves exactly that problem — and once it clicks, you'll wonder how you ever coded without it. This guide walks you through everything from installing Git to confidently collaborating on GitHub, with real commands you can copy and run right now.


Why Git Matters (Even for Solo Projects)

Git is a version control system: it tracks every change to your code over time, lets you undo mistakes, experiment safely in branches, and collaborate with other developers without overwriting each other's work. GitHub is a cloud platform built on top of Git that hosts your repositories online and adds collaboration tools like pull requests and issue tracking.

Think of Git as the engine, and GitHub as the garage where you park and share your car.


Step 1: Install and Configure Git

Download Git from git-scm.com, or install it via your terminal:

# macOS (with Homebrew)
brew install git

# Ubuntu/Debian
sudo apt install git

# Windows
# Download and run the installer from git-scm.com

Once installed, tell Git who you are — this information gets attached to every commit you make:

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

Verify everything worked:

git --version
git config --list

Step 2: The Core Git Workflow

Every Git project follows the same basic loop: edit files, stage the changes you want to save, then commit them as a snapshot. Here's what that looks like end to end.

Initialize a repository

mkdir my-project
cd my-project
git init

Check what's changed

git status

This is the command you'll run more than any other. It tells you which files are modified, staged, or untracked.

Stage your changes

git add filename.txt      # stage a specific file
git add .                 # stage everything in the current directory

Commit your changes

git commit -m "Add user login form"

A good commit message describes what changed and why — future you (and your teammates) will thank you.

View your history

git log --oneline

This shows a compact list of every commit, letting you see exactly how your project evolved.


How Code Moves From Your Machine to GitHub

Before we get into branching, it helps to see the full picture of where your code actually lives at each stage of the workflow — your working directory, Git's staging area, your local repository, and finally GitHub itself.


Step 3: Branching — Working Without Fear

Branches let you work on new features or fixes in isolation, without touching your main codebase until you're ready.

# Create and switch to a new branch
git branch feature-login
git checkout feature-login

# Or do both in one step
git checkout -b feature-login

On newer versions of Git, you can also use the more explicit switch command:

git switch -c feature-login
Git Branching Diagram

Once your feature is done and tested, merge it back into your main branch:

git checkout main
git merge feature-login

If both branches changed the same lines of code, Git will flag a merge conflict — don't panic, we'll cover exactly how to resolve one further down.


Step 4: Connecting to GitHub

Create a repository on GitHub

Go to github.com/new, name your repository, and skip adding a README if you already have a local project.

Link your local project to GitHub

git remote add origin https://github.com/yourusername/your-repo.git

Push your code

git push -u origin main

The -u flag sets up tracking, so from now on you can simply run git push.

Pull changes from GitHub

If you're working across multiple machines or with teammates, pull the latest changes before you start working:

git pull origin main

Clone an existing repository

git clone https://github.com/someuser/some-repo.git

Step 4.5: Set Up SSH Authentication (Recommended)

GitHub no longer accepts plain passwords over the command line, and typing a personal access token every time you push gets old fast. SSH keys solve this permanently.

Generate a key pair on your machine:

ssh-keygen -t ed25519 -C "you@example.com"

Press Enter to accept the default file location, then copy your public key:

# macOS
pbcopy < ~/.ssh/id_ed25519.pub

# Linux
cat ~/.ssh/id_ed25519.pub

# Windows (PowerShell)
Get-Content ~/.ssh/id_ed25519.pub | Set-Clipboard

On GitHub, go to Settings > SSH and GPG keys > New SSH key, paste the key, and save. From now on, switch your remote URL to the SSH format instead of HTTPS:

git remote set-url origin git@github.com:yourusername/your-repo.git

Test the connection:

ssh -T git@github.com

A successful response confirms you're authenticated, and you'll never need to type a password or token to push again.


Git Best Practices That Actually Matter

Git has dozens of commands, but a handful of habits separate a clean, navigable repository from a confusing one:

  • Commit often, in small chunks. A commit that says "fix bug" and touches 40 files is much harder to review or revert than five focused commits.
  • Write commit messages in the imperative mood. "Add login validation," not "Added login validation" or "Adding login validation." This matches Git's own conventions and reads naturally in logs.
  • Never commit secrets. API keys, passwords, and .env files should never enter version control — use .gitignore from day one, and if a secret does slip through, rotate it immediately rather than just deleting the commit.
  • Pull before you push. Running git pull before you start a work session avoids painful conflicts caused by working on outdated code.
  • Name branches descriptively. feature-user-auth or fix-navbar-overlap tell you (and your teammates) exactly what's inside, unlike branch2 or test.
  • Don't rewrite history on shared branches. Commands like git rebase and git push --force are powerful, but using them on a branch others are actively working from can overwrite their commits entirely. Reserve force-pushes for your own private feature branches.

Step 5: Collaborating with Pull Requests

A pull request (PR) is how you propose merging your branch into someone else's project — or your own team's main branch — with a chance for review before anything gets merged.

  1. Push your feature branch to GitHub: git push origin feature-login
  2. Open GitHub and click Compare & pull request
  3. Describe what your change does and why
  4. Request a review from a teammate, or merge it yourself on solo projects
  5. Once approved, click Merge pull request

Pull requests aren't just a formality — they create a paper trail of every decision made in your codebase, which is invaluable when you're debugging something six months later.


Common Real-World Scenarios

"I committed something I shouldn't have"

# Undo the last commit but keep your changes
git reset --soft HEAD~1

# Undo the last commit and discard the changes entirely
git reset --hard HEAD~1

Use --hard carefully — it permanently discards uncommitted work.

"I need to ignore certain files"

Create a .gitignore file in your project root to stop Git from tracking things like dependencies or environment files:

node_modules/
.env
.DS_Store
*.log

"I have a merge conflict"

When Git can't automatically combine changes, it marks the conflicting section directly in the file:

<<<<<<< HEAD
your version of the code
=======
their version of the code
>>>>>>> feature-branch

Edit the file to keep the correct version (or a combination of both), remove the conflict markers, then stage and commit:

git add filename.txt
git commit -m "Resolve merge conflict"

"I want to save work without committing yet"

git stash        # temporarily shelve changes
git stash pop    # bring them back later

Your Git & GitHub Cheat Sheet

Command What it does
git init Start tracking a new project
git status See what's changed
git add . Stage all changes
git commit -m "message" Save a snapshot
git branch List branches
git checkout -b name Create and switch to a branch
git merge branch-name Merge a branch into the current one
git push origin main Upload commits to GitHub
git pull origin main Download the latest changes
git clone url Copy a repository locally
git log --oneline View commit history

Need Expert Git & Version Control Support?

Managing complex branch merges, resolving intricate merge conflicts, structuring large monorepo filesystems, or setting up secure GitHub Actions automation blocks can be challenging. Our expert technical team is here to assist! Reach out directly via our Contact Us page or drop us an email at support@alerts24x7.com for professional workflow consulting.


Final Thoughts

Git rewards you the moment you stop being afraid of it. Commit early, commit often, branch freely, and don't be afraid to experiment — that's the entire point of version control. The commands in this guide cover the 90% of Git you'll use daily; everything else you can look up when you actually need it.

Got a Git workflow tip of your own, or a scenario I didn't cover? Drop it in the comments — I'll add the best ones to this guide.

Previous Post Next Post