Practical Git Workflows and Conflict Resolution

Standard Synchronization and Commit Workflow

Always synchronize your local repository with the remote before pushing new changes to prevent integration conflicts.

git fetch origin
git pull origin main

The recommended sequence for persisting local modifications is:

git add .
git commit -m "Implement dashboard feature"
git pull origin main
git push origin main

Avoid bypassing pre-commit hooks using --no-verify unless absolutely necessary, as these hooks enforce code quality and catch potential defects early.

If you need to synchronize remote updates but are not ready to push, execute git pull. In the event of merge conflicts, temporarily revert local changes on the affected files, pull the updates, and then reapply your modifications.

Temporarily Switching Contexts

To switch branches while retaining uncommitted work, stash your changes to clear the working tree, retrieve external updates, and then restore your stashed state.

git stash push -m "WIP: dashboard styling"
git stash pop

Note that restoring a stash might overwrite newly pulled updates in files you had modified locally.

Integrating Specific Files from Another Branch

To overlay a specific directory or file from a different branch into your current working tree without a full merge:

git restore --source=feature/auth src/utils/helpers.ts

Feature Branch Integration

When merging an isolated feature into the primary development line:

git push origin feature/dashboard
git switch main
git pull origin main
git merge feature/dashboard
git push origin main

Branch Creation and Remote Tracking

Prior to creating or switching branches, ensure local metadata reflects the remote state:

git fetch --all

Switching to an Existing Branch

git switch feature/auth
git pull origin feature/auth

Creating a New Local Branch

If the remote lacks the branch, generate and push it:

git switch -c feature/auth
git push -u origin feature/auth

The -u flag establishes an upstream tracking relationship, simplifying future pushes and pulls.

Linking to an Existing Remote Branch

git switch -c feature/auth origin/feature/auth

Extracting Commits Across Branches

To apply specific commits from a target branch into your current context, identify the commit hash via git log and apply it:

git cherry-pick a1b2c3d

Branch Inventory

git branch          # Local branches
git branch -r      # Remote references
git branch -a      # All branches

Branch Deletion

Ensure you are operating from a separate branch before removing a target branch.

git branch -D feature/legacy
git push origin --delete feature/legacy

Resolving Common Push Failures

Interrupted Rebase

If a rebase operation halts prematurely, leaving a locked state, you can either forcefully clear the rebase state or resolve the conflicts and proceed:

rm -rf .git/rebase-merge
# OR
git rebase --continue

Remote Divergence

When the local history is out of sync with the remote, a pull is required before pushing. Using rebase during the pull can maintain a cleaner commit history:

git pull --rebase origin main
git push origin main

Branch Name Mismatch

Push rejections due to incorrect branch names are common. Always verify the active branch using git branch and copy the exact name to avoid typographical errors.

Tags: Git Version Control Workflow Branching

Posted on Wed, 07 Oct 2026 16:25:25 +0000 by santrowithu