Skip to content

Instantly share code, notes, and snippets.

View QZLin's full-sized avatar

Q.Z.Lin QZLin

View GitHub Profile
@QZLin
QZLin / extract-git-folder-with-history.md
Created October 14, 2021 05:05 — forked from cyberang3l/extract-git-folder-with-history.md
GIT: How to extract a specific folder from a git repository branch, including the folder's related git history only

GIT: How to extract a specific folder from a git repository branch, including the folder's related git history only

NOTE: If you want to keep the history for a specific folder in the master branch, just skip steps in lines 3,4,5,6,7

git clone <git-repository-url>
cd <git-repository-dir>

git checkout <branch-name>              # line 3; Checkout the branch of interest
git merge --strategy=ours master        # line 4; keep the content of this branch only and record a merge
git checkout master                     # line 5; Go back to the master branch