Step-by-Step Git Commands Guide

Published: (April 5, 2026 at 02:00 PM EDT)
2 min read
Source: Dev.to

Source: Dev.to

Initial Setup

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

# Initialize a new repository
git init

# Add a remote GitHub repo
git remote add origin https://github.com/username/repo.git

Basic Workflow

# Check repo status
git status

# Stage files
git add filename.js
git add .   # add all files

# Commit changes
git commit -m "Initial commit"

# Push to remote (main branch)
git push origin main

Branching

# Create new branch
git branch develop

# Switch to branch
git checkout develop

# Create + switch in one step
git checkout -b feature/login-auth

# List branches
git branch

Merging

# Merge feature into develop
git checkout develop
git merge feature/login-auth

# Merge staging into main
git checkout main
git merge staging

Syncing with Remote

# Pull latest changes
git pull origin develop

# Push branch to remote
git push origin develop

Maintenance

# Delete local branch
git branch -d feature/login-auth

# Delete remote branch
git push origin --delete feature/login-auth

# View commit history
git log --oneline --graph --decorate

Hotfix Flow

# Create hotfix branch from main
git checkout main
git checkout -b hotfix/critical-bug

# After fix
git commit -m "Fix critical bug"
git push origin hotfix/critical-bug

# Merge back into main and develop
git checkout main
git merge hotfix/critical-bug
git checkout develop
git merge hotfix/critical-bug
0 views
Back to Blog

Related posts

Read more »

Cx Dev Log — 2026-04-05

Overview Merging branches isn’t usually the most thrilling part of a project, but it’s crucial for keeping the bigger picture in sync. Today I focused on branc...