我想拥有一个存储库,其中master是由其自身分支中的代码组成的。
用例是该存储库将包含多种不同语言的示例代码,这些代码将独立开发,但将具有共享的测试,脚本和配置以应对第三方持续集成。
这可能吗?有更好的方法吗?
答案 0 :(得分:0)
我想你可以做得很简单。只需添加子模块->将当前存储库指定为源链接->并切换到所需的分支。 但是,为了避免混淆,也许值得更改当前存储库的结构?将共享的测试,脚本等放在单独的存储库中;然后使用不同的语言为这些示例代码创建存储库->添加为具有共享内容的子模块存储库->并将这些存储库用作主存储库中的子模块。 或者,可以在同一单独的存储库中但在不同的分支中开发示例代码。然后,您将拥有3个存储库:主存储库,带有示例代码的存储库和共享内容的存储库。
答案 1 :(得分:0)
这是我最终使用的解决方案:
# Enter desired directory
cd ~/Documents/GitHub/
# Create a directory to contain the branches
mkdir Branches-as-Submodules
# Enter directory
cd Branches-as-Submodules
# Clone
git clone https://github.com/brianjenkins94/Branches-as-Submodules.git master
# Create a branch module
git checkout project1
git push --set-upstream origin project1
# Two for good measure
git checkout project2
git push --set-upstream origin project2
# Clone branches
git clone --branch project1 https://github.com/brianjenkins94/Branches-as-Submodules.git project1
git clone --branch project2 https://github.com/brianjenkins94/Branches-as-Submodules.git project2
# Enter master
cd master
# Configure submodule(s)
git submodule add --branch project1 https://github.com/brianjenkins94/Branches-as-Submodules.git project1
git submodule add --branch project2 https://github.com/brianjenkins94/Branches-as-Submodules.git project2
# Add changes
git add .
# Commit changes
git commit -m "Added submodule(s)"
# Push changes
git push origin master:master
# Feel free to make changes to any branch at this point (not using checkout)
# But at some point come back to master and run:
git submodule update --remote
git add .
git commit -m "Updated submodule(s)"
git push origin master:master
# Final note: In the installation instructions of your README, have the consumer use:
git clone --recursive https://github.com/brianjenkins94/Branches-as-Submodules.git