How to share git branches that are based on same repository?

喜欢而已 提交于 2019-12-08 03:16:53

问题


I am a novice programmer, and completely new to GitHub. I am collaborating with a colleague on a project he has been working on over the years.

So Far:

He created a repository and loaded up all the initial files. I forked it into my account, so that I could work on it separately.

Now:

How can I make a commit to my repository and share it with him, so that he can check out the changes and incorporate them into his repository IF he likes the changes?

I know there is a lot of information on GitHub, but I'm not even sure where to start. Any help is greatly appreciated.


回答1:


There are many ways to do this, github recommends pull requests and unless you have no push access to the repository you will need to do this or send patches. There is an example of such a workflow here

git clone git@github.com:<their repo> [optional folder name]
cd reponame (or optional folder name)

If the repository has submodules then

git submodule update --init (if the repo has submodules)
git submodule foreach 'git checkout <their working branch>'

Fork the code. Fork the specific repository you plan to work on. This will give you your own copy of the project. Set up git in the repository you plan to work on.

cd <repo dir or optional one chosen)
git remote set-url origin git@github.com:<your github name>/<your repo>.git
git remote add --track next upstream git://github.com/<their github name>/<their repo>.git

That is your repository set up to help with code. You can do git pull, git push, etc. (this will be to/from your fork). To pull in changes from a branch of the partner repo, just do:

git pull upstream branch

You will not be able to git push to their repo, for that you need to do a pull request.

When you are happy then go to github (your project) and select diff and pull request. This allows you to put in a message and the lib maintainer will get a message to attend to the request. It will also show if your pull request will merge cleanly, it is unlikely to be accepted if the maintainer has to fix code.




回答2:


  • Clone
  • Make Changes and Track it
  • Commit
  • Push to your github repo
  • Pull to your friends repo

Recommended approach in your case is collaborating with your friend.

Here is how:

Add a collaborator

Read this: Will give you basics of git and how to collaborate with others.



来源:https://stackoverflow.com/questions/17746594/how-to-share-git-branches-that-are-based-on-same-repository

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