tags:

views:

58

answers:

3

Hi all,

I'm having a blog-project on GibHub, where a friend of mine, wants to base his code on. He will make some changes to some files that he do not wish to commit back to me (maybe stylesheets and images), but he will maybe implement a new feature that he would like to push back to my project.

He should also be able to get new code from me, where he would like to get all new stuff.

I've looked around, and it seams that Rebase is the way to go for him, to get updates from me, but how can he most easily push a feature back to me? (He is just learning Git, as well as me)

+2  A: 

He should create a branch which will mirror your "upstream" branch, commit/merge/cherry-pick to it the commits he wants to push upstream, and sometimes do a git-push to a branch in your repo. Then you should review the commits in that branch and merge them to your main branch.

wRAR
Pushing to non-bare repositories is ill advised. Here's a thread from kerneltrap that discusses the possible data loss pitfalls and the hoops you have to jump through to recover:http://kerneltrap.org/mailarchive/git/2007/3/18/241553
jkyle
Aren't github repos bare?
wRAR
+5  A: 
git clone git://yourrepo.com/project.git

Create a tracked remote branch. This means that pulls and push operations are automatically done with the main branch. The track branch might be origin/dev or origin/master. Whichever.

git checkout --track -b mylocalbranch origin/trackedbranch

After that a normal git work flow is done with local commits and such. Occasionally he should,

git pull --rebase

This will perform a rebase operation which rolls back his changes, pulls in the changes made to the remote branch, then replays his local changes on top of that (resolve any conflicts; perform any merges).

When he's done and wants to make those changes live, he should bring things current:

git pull --rebase # get most recent changes

Then, for a bare repository:

git push # push his changes to the main repo

If it's a non-bare repository (like your repository in your home folder or some such), then it's preferred that he notify you that he's ready and then you do the

git pull /path/to/his/repo

It's generally advised not to push to non-bare repositories. The reason being you could have uncommitted changes in your local and when he pushes to it, chaos can ensue details. Kernel trap thread discussing this pit fall

jkyle
How will he ensure that he don't push the stylesheets to me, for exsample? Or should i pull the feature from him, and just only take the revision i want?
Jesper Blad Jensen aka. Deldy
It's an administrative, not technical, question, so he should check what he merges to the push branch and you should check what you merge to the upstream branch.
wRAR
You'd cherry pick the changes you were interested in. More information is available on GitReady: pick out individual commits.http://www.gitready.com/intermediate/2009/03/04/pick-out-individual-commits.html
Damien Wilson
As Damien mentions, this would be a cherry picking situation. You could create a special local branch that he could push to that you could check periodically and cherry pick from. That might be reasonable if he had access to your client, but you did not have access to his. Personally, I only allow read access to my working (non-bare) repositories. This would seem to be particularly important if the person pushing was not aware of the mentioned pitfalls of pushing to it...in any case, I'd rather set up a central bare repository.
jkyle
Yes, so I would make a "FriendBranch", and he would say "git push origin/FriendBranch", right?
Jesper Blad Jensen aka. Deldy
Could i maybe let him make a patch, send it via email, that i then apply? I know its oldschool, but that may suit him best.Will he then still be able to rebase, or will he get merge conflicts when he rebases?
Jesper Blad Jensen aka. Deldy
You could do patches, git was made with email patches in mind (linus spends most of his day auditing and applying patches received through email). If he sets up a tracking branch, he doesn't even need to specify the remote. He'd just "git push". But here's a pit fall with that. He has write permissions to your local and he's working furiously on a frustrating problem. Finally solves it and in his excitement to share, he does "git push origin/dev". You have uncommited changes and it's a non-forward commit....oops. It's really not that tough for you to pull.
jkyle
If you do patches, you're introducing another layer as well that adds to the learning curve. I'd stick with basics at first http://andrewprice.me.uk/weblog/entry/generating-patch-emails-with-git
jkyle
Thanks krunk for points. The thing is though that patches is quite easy to make in tortouse git (what I will tell him to use), so it's actually easier to do than to learn him to get a ssh key to push to github, learn him to cherry-pick or at least push to a special branch, and then for me to integrate. And all this stuff is new to me two. :) but I see how your method is better, but that will also make his code public, and maybe he will not like that. But thanks you all, for your answers :)
Jesper Blad Jensen aka. Deldy
A: 

It seems like you are describing a workflow where a feature is developed concurrently with the main branch. The answers above are good, but it should be noted that a "rebase" is not always necessary. Especially for a git beginner, since a rebase amounts to a history modification, is an intermediate concept, and is not always what you want if you want to keep information about where and when a branch is made in your commit history.

When your friend wants to pull in changes from your main branch, he can always use plain, vanilla merge instead of rebase:

git fetch origin
git merge origin/master  # or any branch he wants to merge other than "master"

When you want to pull your friend's changes, you can do a similar operation:

git fetch friend
git merge friend/feature  # choose any of your friend's branches to merge with your current

The above workflow works if you have a URL (local or otherwise) to his repository. Pushing to a non-bare repository (yours) is dangerous, as noted above. If you need your friend to be able to push, use a public, bare repository.

If you want to only select specific revisions from your friend's branch to pull, use the cherry-pick command:

git fetch friend
git log friend/feature  # or `git log friend`
# find the commit you want to cherry pick, then
git cherry-pick <commit>
Santa