开发者

How do you manage your forked reusable apps on django with git

开发者 https://www.devze.com 2023-02-18 04:45 出处:网络
I am developing a project using django. I am using git for version controlling it. I want to use some reusa开发者_如何学Pythonble django apps e.g. django-mailer for the project. I am planning to fork

I am developing a project using django. I am using git for version controlling it.

I want to use some reusa开发者_如何学Pythonble django apps e.g. django-mailer for the project. I am planning to fork the github repo and clone it to project folder. But that will bring a git repo inside another. I am also not sure if fork is needed or not.

How you are handling similar scenario? Any best practices?


Using virtualenv (or even better virtualenvwrapper) plus pip plus requiremens.txt will allow you to keep you environment clean.

requirement.txt allow you to use git repo as an app source, and even you can specify a specific version/tag/branch to use.


In situations where you want a Git repo inside a Git repo, you should consider Git submodules. Git submodules provide a means for including a separate Git repo inside your own and managing what version it stays at within your code base.

The basic workflow is as follows:

  1. Inside your "parent" project, add any other repos you want with the git submodule add command. For example, git submodule add https://github.com/jtauber/django-mailer.git will put a django-mailer folder in your project; you can specify an alternative name just like you do with git clone if desired.
  2. This automatically clones that repo and by default checks out its master branch. It also adds this information to your Git repo's index, so you'll see if you run git status that you have something to commit.
  3. In your "parent" project (not inside the submodule), run git commit -m "Your message" to commit what you've done.

Later, if you need to update the submodule (the git repo within your git repo), then navigate into it directly and do the standard git pull origin master. If there are updates, go back up into your parent project, do a standard git add and git commit to commit the fact that your repo depends on a newer version of the submodule.

Now, if you later clone your project somewhere else, by default the submodules won't pull their code down at the same time; your parent project just stores which commit your submodules should be at, not their actual code. In this situation, you need to initialize and then update your submodules with the following commands:

git submodule init
git submodule update

Now your submodules should have their code as well.

All of this is detailed in the Git community book. There's also a nice video on Blip.tv showing the git submodule workflow.


I personally use buildout + mr.developer which can download git/mercurial repos and adds those apps to eggs folder.

Forking is only required if you want to update that app to your own needs, if its fine how it works, forking is not needed (just clone). If you don't want that app to be updated by others (that it could possibly crash something) simple copy/paste/or_clone_without_auto_updates/fork does the job.

To handle repository within a repository (inception?) the best practice for me is using something like buildout, maybe fabric would (well it should) do the job.

P.S. I'll post blog article about basics of buildout, i could send a link latter on if interested.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号