Summary: A short, simple guide to take the file state from branch-b (for example the tree at commit commit-b) and make that state a new commit on branch branch-a — without creating a merge commit or linking histories.
Use this when you want branch-a to contain the same file contents as branch-b (the working tree of commit-b) but you do not want to perform a git merge or record branch-b as a parent in history. This produces a normal commit on branch-a whose snapshot equals commit-b.
- Make sure your working tree is clean (stash or commit any local changes).
git status # verify clean working tree- Switch to branch
branch-a.
git switch branch-a- Overwrite the working tree with the files from
branch-b.
git checkout branch-b -- .This replaces the files in your working tree and index (for tracked files) with the versions from branch-b.
- Create the new commit on
branch-a.
git commit -m "Apply state of branch-b (commit commit-b) to branch-a"- Verify.
git log --oneline -n 3
git diff HEAD^ HEAD # show the snapshot change you just madegit checkout branch-b -- .updates tracked files to the tree frombranch-b. Untracked files onbranch-bare not copied. Ifbranch-bhas generated files you need, handle them separately.- This creates a new commit on
branch-a. History does not referencebranch-borcommit-b; it just has the same content snapshot. - If there are important local changes on
branch-a, make sure to commit or stash them first. - Conflict handling: if
git checkout ... -- .fails for some paths or you want a more controlled apply, consider usinggit restore --source=branch-b --worktree --staged .(modern command) or a temporary merge strategy — but the above is simplest. - Pushing: because this is a normal commit on top of
branch-a, a regulargit pushwill work (no force required) unless remote diverged.
Apply state of branch-b (commit commit-b) to branch-a
Copied file tree from branch-b (commit-b) and committed as a new snapshot on branch-a.
This is NOT a merge — history remains linear on branch-a.
-
git statusis clean - You are on
branch-a(git switch branch-a) - You have reviewed the changes (
git diffafter step 3)
That’s it — a simple, safe way to copy the exact file state from branch-b into branch-a as a new commit (no merge parent). Want a tiny script that runs these steps and prints checks? I can add one.