EllisLab text mark
Advanced Search
     
Github and keeping a fork / clone up to date
Posted: 14 November 2012 04:23 PM
Avatar
Joined: 2009-05-17
1444 posts

So, I’ve only got minimal experience with Git and Github, and I have a question.

I forked CodeIgniter. I cloned my CodeIgniter fork to my computer. CodeIgniter had some commits that I want to pull in to my fork on Github, and my clone on my computer so that the fork and clone stays up to date. What do I do?

What would I do if I want to keep my fork and clone up to date with those commits, but I’ve also been working on code of my own? Should I be working on a branch on my clone?

 Signature 

Brian
Brian’s Web Design - Temecula
Community Auth - CodeIgniter Authentication Application

 
Posted: 14 November 2012 06:03 PM   [ # 1 ]   [ Rating: 0 ]
Joined: 2011-02-23
882 posts

If you were working on changes of the CI code you would theoretically branch off the develop branch to something called feature/* or anything else. But basically you’d never change lines of code in master or develop.
Especially if you have forked another user’s repository. You’ll run into conflicts when pulling their changes and when filing a pull request.

I assume though you know how to pull remote changes wink

That’s all just my humble opinion after using .git for almost a year - yet I have been working with .svn before, which was a pain in the you-know-where compared to .git.

 Signature 

ignited Community Framework (WiP)  |  Read the User’s Guide. It won’t bite.

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

CI example .htaccess

 
Posted: 14 November 2012 07:20 PM   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2009-05-17
1444 posts

OK, so I basically answered my own question by reading the documentation on Github. Go figure, reading documentation and actually learning something.

Apparently I had to create a new remote, pointing to EllisLab’s CodeIgniter repository:

git remote add upstream https://github.com/EllisLab/CodeIgniter.git 

Then I fetch the upstream changes:

git fetch upstream 

Then I merge the CodeIgniter develop branch with my own:

git merge upstream/develop 

I need to learn how to manage conflicts and stuff, but I guess I can practice over time and figure that out.

 Signature 

Brian
Brian’s Web Design - Temecula
Community Auth - CodeIgniter Authentication Application

 
Posted: 14 November 2012 11:57 PM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2007-11-28
2435 posts

Yeah, basically your local clone on your computer should have two remotes: origin (the repo you just cloned, likely your fork) and EllisLab’s repo. I’ve personally named mine “cryode” for my fork and “ellislab” for the original, to help make referencing them easier.

Now I use a GUI for a lot of my git stuff (Tower for Mac), so forgive me for not specifying git commands. If I’m not making any changes and just want to keep my repo up to date, I’ll PULL from ellislab, and then PUSH those commits to my fork.

If I’m adding code, I actually use Git Flow to really quickly create a feature or bug branch, because it’s faster (and I can deal with an occasional Terminal command). But as PhilTem said, I always make changes in a branch, as it makes dealing with conflicts and merges easier.

 
Posted: 15 November 2012 05:42 AM   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2012-01-09
136 posts
skunkbad - 14 November 2012 07:20 PM

OK, so I basically answered my own question by reading the documentation on Github. Go figure, reading documentation and actually learning something.

Apparently I had to create a new remote, pointing to EllisLab’s CodeIgniter repository:

git remote add upstream https://github.com/EllisLab/CodeIgniter.git 

Then I fetch the upstream changes:

git fetch upstream 

Then I merge the CodeIgniter develop branch with my own:

git merge upstream/develop 

I need to learn how to manage conflicts and stuff, but I guess I can practice over time and figure that out.

This is the one of 2 ways to do it, but it’s both the hard and the improper one. You should do this instead (no remotes needed):

git pull git@github.com:<user/organization>/<repository>.git <branch>

// or

git pull git@github.com:EllisLab/CodeIgniter.git develop 

Using remotes is fine and is good for comparing changes between your fork and the upstream repository:

git diff upstream/develop # will show you differences between your current working tree and the upstream repository

git diff origin/develop # will show you difference between your current working tree and your online fork 

... but it also requires you to regularly (and manually) fetch updates via e.g. git fetch upstream AND you’re actually merging changes as if they are from another branch instead of only pulling the most recent commits.

Otherwise it’s good practice to keep the master, develop and any branches existing in the upstream repo clean and create a new branch for anything that would be modified by you. And this is essential if you’ll be submitting a pull request.

 
Posted: 15 November 2012 04:35 PM   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2009-05-17
1444 posts

Thanks for the input.

Narf, are we able to submit new features to 2.1 stable?

 Signature 

Brian
Brian’s Web Design - Temecula
Community Auth - CodeIgniter Authentication Application