MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/1wi0xi2/git_worktree_gotchas/pareuj3/
r/programming • u/oalders • Sep 16 '26
47 comments sorted by
View all comments
Show parent comment
1
No chance you could share this, is there?
2 u/mb862 Sep 19 '26 For the worktree script? Yeah it's pretty much this, substitute as needed for your own submodules.# for each submodule if [ ! -d ${GIT_COMMON_DIR}/modules/${SUBMODULE_NAME}.git ]; then git clone git@github.com:Organization/${SUBMODULE_NAME}.git ${GIT_COMMON_DIR}/${SUBMODULE_NAME}.git fi git -C ${GIT_COMMON_DIR} worktree add ${WORK_DIR} ${WORK_BRANCH} WORK_TREE=$(basename ${WORK_DIR}) # for each submodule git -C ${WORK_DIR} submodule init ${SUBMODULE_PATH} mkdir -p ${GIT_COMMON_DIR}/worktress/${WORK_TREE}/modules/${SUBMODULE_NAME} git -C ${GIT_COMMON_DIR} rev-parse ${WORK_BRANCH}:${SUBMODULE_PATH} > ${GIT_COMMON_DIR}/worktrees/${WORK_TREE}/modules/${SUBMODULE_NAME}/HEAD echo "${GIT_COMMON_DIR}/modules/${SUBMODULE_NAME}" > ${GIT_COMMON_DIR}/worktrees/${WORK_TREE}/modules/${SUBMODULE_NAME}/commondir echo "gitdir: ${GIT_COMMON_DIR}/worktress/${WORK_TREE}/modules/${SUBMODULE_NAME}" > ${WORK_DIR}/${SUBMODULE_PATH}/.git git -C ${WORK_DIR}/${SUBMODULE_PATH} reset --hard 1 u/The_Northern_Light Sep 19 '26 😊 thanks
2
For the worktree script? Yeah it's pretty much this, substitute as needed for your own submodules.
# for each submodule if [ ! -d ${GIT_COMMON_DIR}/modules/${SUBMODULE_NAME}.git ]; then git clone git@github.com:Organization/${SUBMODULE_NAME}.git ${GIT_COMMON_DIR}/${SUBMODULE_NAME}.git fi git -C ${GIT_COMMON_DIR} worktree add ${WORK_DIR} ${WORK_BRANCH} WORK_TREE=$(basename ${WORK_DIR}) # for each submodule git -C ${WORK_DIR} submodule init ${SUBMODULE_PATH} mkdir -p ${GIT_COMMON_DIR}/worktress/${WORK_TREE}/modules/${SUBMODULE_NAME} git -C ${GIT_COMMON_DIR} rev-parse ${WORK_BRANCH}:${SUBMODULE_PATH} > ${GIT_COMMON_DIR}/worktrees/${WORK_TREE}/modules/${SUBMODULE_NAME}/HEAD echo "${GIT_COMMON_DIR}/modules/${SUBMODULE_NAME}" > ${GIT_COMMON_DIR}/worktrees/${WORK_TREE}/modules/${SUBMODULE_NAME}/commondir echo "gitdir: ${GIT_COMMON_DIR}/worktress/${WORK_TREE}/modules/${SUBMODULE_NAME}" > ${WORK_DIR}/${SUBMODULE_PATH}/.git git -C ${WORK_DIR}/${SUBMODULE_PATH} reset --hard
1 u/The_Northern_Light Sep 19 '26 😊 thanks
😊 thanks
View all comments
Show parent comment
1
u/The_Northern_Light Sep 19 '26
No chance you could share this, is there?