Git & GitHub Enterprise Guide: Version Control, Branching, CI/CD and Production Workflows
A production-focused guide covering Git internals, branching strategies, pull requests, GitHub, security, CI/CD integration, troubleshooting and enterprise best practices.
Architecture → Automation → Production
Git Overview
Git is a distributed version control system used to track changes, collaborate on software, manage infrastructure as code, and support modern DevOps workflows. GitHub builds on Git by providing repositories, pull requests, code reviews, automation, security scanning, and collaboration features.
Git Architecture
Git stores snapshots of files in a directed graph of commits. Every clone contains the full repository history, enabling offline work, branching, merging, and recovery.
Working Directory → Staging Area → Local Repository → Remote Repository (GitHub)Installation & Configuration
git --version
git config --global user.name "Jane Doe"
git config --global user.email "jane@example.com"
git config --global init.defaultBranch main
git config --global pull.rebase falseRepositories
Initialize or clone repositories, keep a clean directory structure, use .gitignore, and commit small logical changes.
git init
git clone https://github.com/org/project.git
git status
git add .
git commit -m "Initial commit"Commits
Each commit should represent one logical change with a descriptive message. Avoid mixing unrelated changes.
Branches
git switch -c feature/login
git switch main
git branch -aFeature branches isolate work until it is reviewed and merged.
Merge & Rebase
Use merge to preserve branch history and rebase to create a linear history where appropriate. Avoid rebasing shared branches.
git merge feature/login
git rebase mainRemote Repositories
git remote -v
git fetch
git pull
git push origin mainGitHub
Use pull requests, code owners, protected branches, issues, projects, releases, secret scanning and Dependabot to improve software quality and security.
Pull Requests
Require reviews, automated checks, and passing CI before merging.
Branching Strategies
Common enterprise approaches include GitHub Flow, Git Flow and Trunk-Based Development. Choose one strategy consistently across teams.
GitHub Actions
name: CI
on: [pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: echo "Run tests here"Security Best Practices
- Protect main branches.
- Enable MFA.
- Use SSH keys or passkeys.
- Sign commits where required.
- Never commit secrets.
- Enable secret scanning and Dependabot.
Troubleshooting
git status
git log --oneline --graph
git reflog
git restore .
git reset --hard HEAD~1
git stash
git stash popEssential Commands
git init
git clone
git status
git add
git commit
git log
git diff
git switch
git checkout
git branch
git merge
git rebase
git cherry-pick
git tag
git fetch
git pull
git push
git stash
git reflog
git reset
git revertKey Takeaways
Git is the foundation of modern DevOps. Combined with GitHub, protected branches, reviews, CI/CD, and security controls, it enables reliable, auditable, and repeatable software delivery.