How do I organize my Git repo

不羁岁月 提交于 2019-11-30 20:52:57

I found your usage of master a bit confusing as I never knew whether you meant the platform repository as a whole or just its master branch.

My solution to this would be the following:

  • You have one central repository for the platform.
  • You have one central repository per project.
  • Every developer has his/her own repository local.

The central platform repository

This is where only the platform code goes to. Use e.g. your existing repo as a starting point here.

The central project repository

This is a clone of the platform repository and keeps all the code of a project. Init it with

$ git clone --bare /path/to/platform

The developer's local repository

Init

You, as a developer, start by cloning the project repository.

$ git clone /path/to/project

Making changes to the project

Now, make your changes, commit them and push them to the projects bare repo.

$ editor some-file
$ git add -p some-file
$ git commit
$ git push

Pull changes made by other developers to the projects bare repo by using git pull.

Making changes to the platform

As you also want to make changes to the platform itself, you also need a way to access the platform repo. So you add it as a remote repo to your local repo:

$ git remote add platform /path/to/platform
$ git fetch platform

As you can see now with git branch -a, your local repo knows about the platform. Now you want to make some changes to the platform. First you create a local branch central which is a clone of the master branch of the platform repo:

$ git checkout -b central platform/master

You can always check which branch you're on by using git branch or git status. Now you make your changes and commit them (to central, where your on). As central is connected to platform/master (checkout cat .git/config) you can push your changes to the platform repo by simply using git push. Also git pull works without any other arguments.

Use git checkout master and git checkout central to change between your branches.

Get a new platform version into your project

Note: You need to have done the work from the previous section.

First change to your platform branch and pull in the new version of the platform:

$ git checkout central
$ git pull

Now go back to your project branch and merge the changes made in the platform into your project branch.

$ git checkout master
$ git merge central

If a conflict occurs, something like this happens:

$ git merge central
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.

Open the files with the conflicts, resolve them, add them to the staging area and commit the merge:

$ editor index.html
$ git add index.html
$ git commit

Now push your changes to the project's bare repo:

$ git push

More about merge conflicts: Pro Git: Basic Merge Conflicts

If you do not want to change the platforms repo, but merge changes from there into your project use

$ git remote add platform /path/to/platform
$ git fetch platform
$ git merge platform/master

The git remote add is only needed the first time you merge. The other two are always required.


The part about merging is based on the Pro Git Book which is licensed under cc-by-sa. All other content of this post may be considered public domain.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!