Development

Essential GitHub Commands: Complete Guide for Developers

Master essential Git and GitHub commands for version control, branching, collaboration, and workflow automation. A comprehensive reference for developers at all levels.

K

Krishna Vepakomma

Technology Expert

Essential GitHub Commands: Complete Guide for Developers

Git and GitHub are fundamental tools for modern software development, enabling version control, collaboration, and code management. This comprehensive guide covers the essential commands and workflows every developer needs to know.

Getting Started

Git Configuration

Set up Git for first-time use.

Initial Configuration:

# Set your identity
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

# Set default branch name
git config --global init.defaultBranch main

# Set default editor
git config --global core.editor "code --wait"

# View configuration
git config --list

Repository Setup

Create and initialize repositories.

Create New Repository:

# Initialize local repository
mkdir my-project
cd my-project
git init

# Create initial commit
echo "# My Project" > README.md
git add README.md
git commit -m "Initial commit"

# Connect to GitHub
git remote add origin https://github.com/username/my-project.git
git push -u origin main

Clone Existing Repository:

# Clone via HTTPS
git clone https://github.com/username/repository.git

# Clone via SSH
git clone git@github.com:username/repository.git

# Clone to specific directory
git clone https://github.com/username/repository.git my-folder

# Clone specific branch
git clone -b develop https://github.com/username/repository.git

Basic Commands

Daily Workflow Commands

Commands used most frequently.

Status and Changes:

# Check repository status
git status

# View changes in files
git diff

# View staged changes
git diff --staged

# View commit history
git log

# Compact log view
git log --oneline

# Log with graph
git log --oneline --graph --all

Staging and Committing:

# Stage specific file
git add filename.js

# Stage all changes
git add .

# Stage interactively
git add -p

# Commit with message
git commit -m "Add new feature"

# Commit with detailed message
git commit

# Amend last commit
git commit --amend

# Amend without changing message
git commit --amend --no-edit

Working with Remote

Sync with remote repositories.

Push and Pull:

# Push to remote
git push origin main

# Push and set upstream
git push -u origin feature-branch

# Pull changes
git pull origin main

# Fetch without merging
git fetch origin

# Fetch all remotes
git fetch --all

Remote Management:

# View remotes
git remote -v

# Add remote
git remote add upstream https://github.com/original/repo.git

# Remove remote
git remote remove origin

# Rename remote
git remote rename origin upstream

# Change remote URL
git remote set-url origin https://github.com/new/repo.git

Branching

Branch Operations

Create and manage branches.

Branch Commands:

# List branches
git branch

# List all branches (including remote)
git branch -a

# Create branch
git branch feature-name

# Create and switch to branch
git checkout -b feature-name

# Modern way to create and switch
git switch -c feature-name

# Switch to branch
git checkout feature-name
git switch feature-name

# Delete local branch
git branch -d feature-name

# Force delete branch
git branch -D feature-name

# Delete remote branch
git push origin --delete feature-name

# Rename branch
git branch -m old-name new-name

Merging

Combine branch changes.

Merge Commands:

# Merge branch into current
git merge feature-branch

# Merge with commit message
git merge feature-branch -m "Merge feature branch"

# Merge without fast-forward
git merge --no-ff feature-branch

# Abort merge
git merge --abort

# View merge conflicts
git diff --name-only --diff-filter=U

Rebasing

Reapply commits on top of another base.

Rebase Commands:

# Rebase current branch onto main
git rebase main

# Interactive rebase (last 3 commits)
git rebase -i HEAD~3

# Continue after resolving conflicts
git rebase --continue

# Abort rebase
git rebase --abort

# Skip current commit
git rebase --skip

Advanced Operations

Stashing

Temporarily save changes.

Stash Commands:

# Stash changes
git stash

# Stash with message
git stash save "Work in progress"

# List stashes
git stash list

# Apply latest stash
git stash apply

# Apply and remove stash
git stash pop

# Apply specific stash
git stash apply stash@{2}

# Drop stash
git stash drop stash@{0}

# Clear all stashes
git stash clear

# Stash including untracked files
git stash -u

Cherry-Pick

Apply specific commits.

# Apply commit to current branch
git cherry-pick abc123

# Cherry-pick without committing
git cherry-pick abc123 --no-commit

# Cherry-pick range of commits
git cherry-pick abc123..def456

# Abort cherry-pick
git cherry-pick --abort

Resetting

Undo changes and commits.

Reset Commands:

# Unstage file
git reset HEAD filename.js

# Soft reset (keep changes staged)
git reset --soft HEAD~1

# Mixed reset (keep changes unstaged)
git reset HEAD~1

# Hard reset (discard changes)
git reset --hard HEAD~1

# Reset to specific commit
git reset --hard abc123

# Reset single file to commit
git checkout abc123 -- filename.js

Reverting

Create new commits that undo changes.

# Revert specific commit
git revert abc123

# Revert without committing
git revert abc123 --no-commit

# Revert merge commit
git revert -m 1 abc123

Collaboration

Pull Requests

Work with pull requests via CLI.

GitHub CLI Commands:

# Create pull request
gh pr create --title "Feature title" --body "Description"

# List pull requests
gh pr list

# View pull request
gh pr view 123

# Checkout pull request
gh pr checkout 123

# Merge pull request
gh pr merge 123

# Review pull request
gh pr review 123 --approve

Code Review

Review and comment on code.

# View changes in PR
gh pr diff 123

# Add review comment
gh pr review 123 --comment -b "Looks good!"

# Request changes
gh pr review 123 --request-changes -b "Please fix..."

Tags and Releases

Managing Tags

Create and manage version tags.

Tag Commands:

# List tags
git tag

# Create lightweight tag
git tag v1.0.0

# Create annotated tag
git tag -a v1.0.0 -m "Version 1.0.0"

# Tag specific commit
git tag -a v1.0.0 abc123

# Push tag to remote
git push origin v1.0.0

# Push all tags
git push origin --tags

# Delete local tag
git tag -d v1.0.0

# Delete remote tag
git push origin --delete v1.0.0

Releases

Create GitHub releases.

# Create release
gh release create v1.0.0 --title "Version 1.0.0" --notes "Release notes"

# Create release from tag
gh release create v1.0.0

# List releases
gh release list

# Download release assets
gh release download v1.0.0

Useful Workflows

Feature Branch Workflow

Standard development workflow.

# Start new feature
git checkout main
git pull origin main
git checkout -b feature/new-feature

# Work on feature
git add .
git commit -m "Implement feature"

# Update with main
git fetch origin
git rebase origin/main

# Push and create PR
git push -u origin feature/new-feature
gh pr create

Hotfix Workflow

Fix urgent production issues.

# Create hotfix branch
git checkout main
git pull origin main
git checkout -b hotfix/critical-fix

# Make fix
git add .
git commit -m "Fix critical issue"

# Merge to main
git checkout main
git merge hotfix/critical-fix
git push origin main

# Tag release
git tag -a v1.0.1 -m "Hotfix release"
git push origin v1.0.1

Best Practices

Commit Messages

Write meaningful commits.

Format:

type(scope): subject

body (optional)

footer (optional)

Examples:

git commit -m "feat(auth): add OAuth2 login support"
git commit -m "fix(api): resolve null pointer exception"
git commit -m "docs(readme): update installation instructions"
git commit -m "refactor(utils): simplify date formatting"

Branch Naming

Consistent branch names.

Conventions:

feature/user-authentication
bugfix/login-error
hotfix/security-patch
release/v1.2.0
docs/api-documentation

Working with Innoworks

At Innoworks Software Solutions, we use Git and GitHub best practices to ensure code quality and efficient collaboration.

Our Development Practices

Version Control:

  • Feature branch workflow
  • Code review requirements
  • Automated CI/CD
  • Release management

Conclusion

Mastering Git and GitHub commands is essential for effective software development. From basic operations to advanced workflows, these tools enable version control, collaboration, and code management at any scale.

Practice these commands regularly, establish team conventions, and leverage automation to streamline your development workflow. Partner with experienced developers like Innoworks who follow industry best practices for version control and collaboration.

Need help with software development? Contact Innoworks to discuss how we can help you build high-quality applications with modern development practices.

Ready to Build Something Amazing?

Let's discuss how Innoworks can bring your vision to life. Get a free consultation with our technology experts.

Get Free Consultation

No commitment required. Response within 24 hours.

Share this article

Stay Ahead of the Curve

Get weekly insights on AI, software development, and industry trends from our engineering team.

Get In Touch

Let's Build Something Amazing Together

Ready to transform your business with innovative technology solutions? Our team of experts is here to help you bring your vision to life. Let's discuss your project and explore how we can help.

MVP in 8 Weeks

Launch your product faster with our proven development cycle

Global Presence

Offices in USA & India, serving clients worldwide

Let's discuss how Innoworks can bring your vision to life.