Git Branch Workflow – From Dev to Deployment

30/04/2025


article cover

Introduction


If you’ve never used Git before, think of it as a time machine for your code — it keeps track of every change you make and lets you work safely without fear of “breaking” your project.

A common setup is:

  1. You work in a development branch (dev) where you can freely make and test changes.
  2. Once things are ready, you merge those changes into the main branch (main), which is what you use for the stable version of your project.

Let’s break it down step by step.

Part 1 – Everyday Commands


Switching Branches

git switch dev

Moves you to the dev branch. Replace dev with any branch name you want to work on.


Checking Current Branch & Status

git status

Shows:


Adding & Committing Changes

git add .
git commit -m "Added contact form"

Adds all changes and commits them with a short message.


Pushing Changes to GitHub

git push

Pushes commits to GitHub. If it’s a new branch:

git push origin dev

Creating a New Branch

git checkout -b new-feature
git push -u origin new-feature

Creates a branch and pushes it to GitHub for the first time.

Part 2 – Pull Requests


A Pull Request (PR) is a way to propose changes from one branch to another while letting you review and approve them first.

Steps:

  1. Push your dev branch to GitHub.
  2. On GitHub, click "Compare & pull request".
  3. Describe your changes.
  4. Click "Create pull request".
  5. Review and merge into main.

Part 3 – Merging


To merge without a PR (directly in Git):

git switch main
git merge dev
git push origin main

Part 4 – Handy Extras


Stashing Work

git stash
git stash pop

Temporarily saves your work and restores it later.


Discarding Changes

git checkout -- filename
git reset --hard

Resets one file or the entire working directory.


Force Push

git push --force

Overwrites the remote branch with your local branch.


Viewing Branch Info

git branch -vv
git branch -a

Shows tracking info and lists branches.


Pulling Changes from GitHub

git pull

Downloads changes from the remote branch you’re on.


Cloning a Repository

git clone https://github.com/user/repo.git

Copies a remote repository to your local machine.


Viewing Commit History

git log --oneline --graph --all

Shows a clean, visual history of commits.


Undoing the Last Commit (Keep Changes)

git reset --soft HEAD~1

Moves HEAD back but keeps your changes staged.


Removing a File from Git (but keep it locally)

git rm --cached filename

Stops tracking the file without deleting it locally.

Conclusion


With a devmain workflow, you can test changes safely and only merge what’s ready.