ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Github and keeping a fork / clone up to date

November 14, 2012 4:23pm

Subscribe [1]
  • #1 / Nov 14, 2012 4:23pm

    skunkbad

    1326 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?

  • #2 / Nov 14, 2012 6:03pm

    PhilTem

    872 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 😉

    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.

  • #3 / Nov 14, 2012 7:20pm

    skunkbad

    1326 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 <a href="https://github.com/EllisLab/CodeIgniter.git">https://github.com/EllisLab/CodeIgniter.git</a>

    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.

  • #4 / Nov 14, 2012 11:57pm

    Aken

    2430 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.

  • #5 / Nov 15, 2012 5:42am

    Narf

    155 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 <a href="https://github.com/EllisLab/CodeIgniter.git">https://github.com/EllisLab/CodeIgniter.git</a>

    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 .(JavaScript must be enabled to view this email address):<user/organization>/<repository>.git <branch>
    
    // or
    
    git pull .(JavaScript must be enabled to view this email address):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.

  • #6 / Nov 15, 2012 4:35pm

    skunkbad

    1326 posts

    Thanks for the input.

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

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases