Advanced Git Workflows for Intermediate to Advanced Git Users
Feature Branch Workflow
The Feature Branch Workflow involves creating a new branch every time you start work on a new feature. This keeps your changes isolated from the main (previously master) branch and ensures that the main branch always contains production-quality code.
# Start by creating a new branch from main
git checkout main
git checkout -b feature-branch
# Make changes and commit them
git add .
git commit -m "Add new feature"
# Push the feature branch to the remote repository
git push -u origin feature-branch
Git Rebase Workflow
Rebasing is a method of integrating changes from one branch into another by reapplying commits on top of another base. It's an alternative to the merge command.
# Start on your feature branch
git checkout feature-branch
# Fetch the latest main branch
git fetch
# Rebase your feature branch onto main
git rebase origin/main
# If there are conflicts, resolve them, then continue the rebase
git add <resolved-file>
git rebase --continue
# After successful rebase, push your changes
# Use --force-with-lease to prevent overwriting others' work
git push --force-with-lease
Git Cherry-Pick Workflow
Cherry-picking in Git means to choose a commit from one branch and apply it onto another. This is useful if you want to apply just a few commits from a feature branch without merging the entire branch.
# Checkout the branch you want to apply the commit to
git checkout main
# Cherry-pick the commit
git cherry-pick <commit-hash>
Forking Workflow
The Forking Workflow is most often seen in open source projects. Every developer has their own server-side repository, which gives them full control over the repository.
# Fork the original repository to your own GitHub account
# Clone your fork locally
git clone <your-fork-url>
# Add the original repository as a remote called "upstream"
git remote add upstream <original-repo-url>
# Sync your fork with the original repository
git fetch upstream
git checkout main
git merge upstream/main
Pull Requests and Code Review Workflow
Pull Requests are the heart of collaboration on GitHub. They let you tell others about changes you've pushed to a branch in a repository.
# Push your feature branch to your remote repository
git push origin feature-branch
# Go to your repository on GitHub and create a pull request for the feature branch
# After the code review, the pull request can be merged into main
Git Tags for Release Management
Tags are used to create stable releases. They mark a specific point in the repository's history.
# Checkout the main branch
git checkout main
# Pull the latest changes
git pull origin main
# Create a new tag
git tag -a v1.0.0 -m "Release version 1.0.0"
# Push the tag to the remote repository
git push origin v1.0.0
Advanced Git Aliases
Git aliases save time by reducing the number of keystrokes needed for commands.
# Set a new alias
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
# Now you can use shorter commands
git co main
git br -a
git ci -m "Commit message"
git st
These workflows represent some of the more advanced techniques that can make managing projects with Git more efficient. Each workflow has its place, and understanding when and how to use them will greatly enhance your Git proficiency.