A comprehensive guide for using GitHub in professional software development environments.
# Configure global settings
git config --global user.name "Your Name"
git config --global user.email "your.email@company.com"
# Check configuration
git config --list# Clone repository
git clone https://github.com/company/project.git
# Initialize new repository
git init
git remote add origin https://github.com/company/project.git# Check status
git status
# Add files
git add . # Add all files
git add filename.py # Add specific file
# Commit changes
git commit -m "Add user authentication feature"
# Push changes
git push origin main
# First time push (sets up tracking)
git push -u origin main # -u sets upstream trackingThe -u (or --set-upstream) flag establishes a tracking relationship:
# With -u: Sets up tracking between local and remote branch
git push -u origin main
# After tracking is set, you can use shorthand:
git push # Automatically pushes to tracked remote
git pull # Automatically pulls from tracked remote
# Check tracking relationships
git branch -vv# Fetch and merge latest changes
git pull origin main
# Fetch without merging
git fetch origin# Create new branch
git checkout -b feature/user-auth
# Switch to existing branch
git checkout main
# List all branches
git branch -a
# Delete branch
git branch -d feature/user-authmain/master- Production codedevelop- Development integrationfeature/feature-name- New featuresbugfix/bug-description- Bug fixeshotfix/critical-fix- Critical production fixes
# 1. Create feature branch
git checkout -b feature/new-api
# 2. Make changes and commit
git add .
git commit -m "Implement new API endpoints"
# 3. Push branch
git push origin feature/new-api
# 4. Create PR on GitHub web interface- Create PR with clear title and description
- Assign reviewers from your team
- Address feedback by pushing new commits
- Merge after approval
- Delete branch after merging
# Merge (preserves commit history)
git merge feature/new-feature
# Rebase (cleaner history)
git rebase main# Save current work temporarily
git stash
# Apply stashed changes
git stash pop
# List stashes
git stash list# Undo last commit (keep changes)
git reset --soft HEAD~1
# Undo last commit (discard changes)
git reset --hard HEAD~1
# Revert specific commit
git revert commit-hash# Reference issues in commits
git commit -m "Fix login bug - closes #123"
# Link PRs to issues
git commit -m "Add user validation - resolves #456"Create .github/workflows/ci.yml:
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: '3.9'
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run tests
run: pytest# Format: type(scope): description
feat(auth): add JWT token validation
fix(api): resolve null pointer exception
docs(readme): update installation instructions
test(user): add unit tests for user service- Require PR reviews before merging
- Require status checks to pass
- Restrict force pushes to main
- Delete head branches after merge
# Python
__pycache__/
*.pyc
.env
venv/
# Node.js
node_modules/
npm-debug.log
# IDE
.vscode/
.idea/
# OS
.DS_Store
Thumbs.db# Generate SSH key
ssh-keygen -t ed25519 -C "your.email@company.com"
# Add to SSH agent
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
# Add public key to GitHub account
cat ~/.ssh/id_ed25519.pub- Use for HTTPS authentication
- Set appropriate scopes
- Store securely (environment variables)
- Rotate regularly
# When conflict occurs
git status # See conflicted files
# Edit files to resolve conflicts
git add resolved-file.py
git commit -m "Resolve merge conflict"# Install Git LFS
git lfs install
# Track large files
git lfs track "*.zip"
git add .gitattributes# Remove untracked files
git clean -fd
# Compress repository
git gc --aggressive# Start new feature
git flow feature start new-feature
# Finish feature
git flow feature finish new-feature
# Create release
git flow release start 1.0.0MAJOR.MINOR.PATCH(e.g., 2.1.3)- Major: Breaking changes
- Minor: New features (backward compatible)
- Patch: Bug fixes
# Create tag
git tag -a v1.0.0 -m "Release version 1.0.0"
# Push tags
git push origin --tags
# Create release on GitHub
# Use GitHub web interface or GitHub CLI- Insights: Repository traffic and contributions
- Security: Vulnerability alerts and dependency scanning
- Actions: CI/CD pipeline monitoring
- Projects: Kanban boards for task management
# Add to ~/.gitconfig
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.unstage 'reset HEAD --'# 1. Create hotfix branch from main
git checkout main
git checkout -b hotfix/critical-security-fix
# 2. Make fix and test
git add .
git commit -m "hotfix: patch security vulnerability"
# 3. Create emergency PR
git push origin hotfix/critical-security-fix
# 4. Merge to main and develop
# 5. Tag release
git tag -a v1.0.1 -m "Hotfix release 1.0.1"# Revert to previous release
git checkout main
git revert commit-hash
# Force reset (use with caution)
git reset --hard previous-commit-hash
git push --force-with-lease origin mainThis guide covers essential GitHub operations for professional software development. Always follow your organization's specific workflows and policies.