Fundamentals 18 min read

Master Git Workflows: From Git Flow to GitHub Flow and Daily Best Practices

This guide walks you through essential Git workflows—including Git Flow, GitHub Flow, and GitLab Flow—covers daily best‑practice tips such as command‑line usage, commit message conventions, .gitignore handling, branch strategies, release tags, merge vs. rebase decisions, history rewriting, hook scripts, shallow cloning, and stash management, all illustrated with clear examples and command snippets.

Open Source Linux
Open Source Linux
Open Source Linux
Master Git Workflows: From Git Flow to GitHub Flow and Daily Best Practices

Quick Interactive Git Learning

For fast, hands‑on Git practice, use the online visual tool at Learn Git Branching , which shows real‑time status without installing any software.

Common Enterprise Git Workflows

Git Flow

Main branch

Develop branch

Feature branches

Release branches

Hotfix branches

GitHub Flow

Create a branch

Make commits

Open a PR

Review and test

Deploy and merge

GitLab Flow

Production branch

Environment branches

Release branches

Daily Best‑Practice Tips

Prefer the command line over GUIs for speed and clarity.

Write clear commit messages: separate subject (≤50 chars) and body (≤72 chars per line), no trailing period on the subject.

Use a .gitignore template and adjust per project.

Develop on feature branches or forks, never directly on the main branch.

Use release branches (e.g., release/1.32) and tags ( A‑feature, B‑bugfix) for version management.

Common Git Commands

# workspace → staging area
git add <file/dir>
# staging area → local repository
git commit -m "some info"
# local repository → remote repository
git push origin master
# discard changes
git checkout -- <file>
# reset staging area to last commit
git reset HEAD <file>
# fetch without merging
git fetch upstream master
# pull with rebase
git pull --rebase upstream master
# reset to a specific commit
git reset <commit>
# hard reset (discard changes)
git reset --hard <commit>
# amend last commit
git commit --amend -m "new message"
# revert a commit
git revert <commit>

Merge vs. Rebase

Use merge when you want to preserve the complete history as a factual record; use rebase for a clean linear history on local, unshared commits. Never rebase commits that have already been pushed.

Updating Commit History

# interactive rebase last 5 commits
git rebase -i HEAD~5
# edit, squash, drop, etc.
# cherry‑pick a specific commit
git cherry-pick -x <commit>
# view reflog and recover lost commits
git reflog
git cherry-pick <commit>

Batch History Modification

Use git filter-branch to rewrite author information, remove sensitive data, or delete large files from the entire history. Always test on a separate branch first.

git filter-branch --commit-filter '
  if [ "$GIT_AUTHOR_EMAIL" == "[email protected]" ]; then
    GIT_AUTHOR_NAME="newname";
    GIT_AUTHOR_EMAIL="[email protected]";
    git commit-tree "$@";
  else
    git commit-tree "$@";
  fi' HEAD

Hook Scripts

Git provides client‑side hooks in .git/hooks (e.g., pre-commit, commit-msg) that can enforce policies such as linting before a commit. Enable a hook by removing the .sample suffix and making it executable.

Pre‑Commit Framework

Install pre-commit via pip and configure .pre-commit-config.yaml to run checks like trailing‑whitespace removal and flake8 before pushes.

# install
pip install pre-commit
# install hook for push
pre-commit install -f --hook-type pre-push
# example config
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
  rev: v2.9.2
  hooks:
    - id: trailing-whitespace
    - id: flake8

Shallow Cloning Large Repositories

Clone only the latest snapshot with --depth=1. To clone a specific tag without full history, initialize an empty repo, add the remote, fetch the tag with depth, and checkout FETCH_HEAD:

git init myproj
git remote add origin http://example.com/repo.git
git -c protocol.version=2 fetch origin 15.0.1 --depth=1
git checkout FETCH_HEAD

For repositories using Git LFS, skip downloading LFS objects during clone with GIT_LFS_SKIP_SMUDGE=1.

GIT_LFS_SKIP_SMUDGE=1 git clone http://example.com/repo.git

Handling Work Interruptions

Use git stash to save uncommitted changes, optionally including untracked files ( -u). Retrieve with git stash apply or git stash pop, and clear with git stash clear.

# stash changes
git stash
# stash including untracked files
git stash -u
# list stashes
git stash list
# apply a specific stash
git stash apply stash@{2}
# pop and remove
git stash pop
# drop a stash
git stash drop stash@{0}

Alternatively, push your current work to a remote branch for backup before switching contexts.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

workflowGitmergerebasebest-practicescommandsversion-control
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.