Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Git: Could I fork an app and then build a new app from it?

I'm building a web app and I've got as far as just a basic Home page, About, and login and sign up. I'm using Git and Github.

I've also pushed it to Heroku.

I'm wondering, since this is a foundation common to most web apps, and I have an idea for another app, I'm wondering if I can create a git branch, and essentially build two different apps from the same base, eventually resulting in two completely separate apps, running on the web.

Essentially, I want to clone this foundation and build 'app number 2' from it. What is the best way to go about this?

Is there a way to sort of 'clone' this app, or would I git branch it do some sort of Git wizardry?

Please bear in mind that I'm pretty new to all this.

2 Answers

Those 3 steps worked. I have a separate folder and separate github repository all setup, local server running the app fine, git push fine. Only thing I haven't tried is setting Heroku up with it.

If you're curious, Maciej, I checked the git config file in the .git folder after I'd done git init, and there was no trace of a github repo, so all good.

So, if anyone's curious, the steps are:

  1. Copy/paste your project folder,
  2. Rename your new folder to whatever you like, let's call it 'project2' for now,
  3. Delete project2's .git folder by using "rm -rf .git",
  4. "git init"
  5. "git add .", "git commit -am "initial commit" "
  6. Setup a new github repository like you normally would. Remember you don't need to setup a new SSH Key - you only need one per computer,
Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

I'd say just copy the folder :). It will retain all the code and git history. The only change you'd have to make is the remote git address so that it doesn't overwrite the original project on your github. No need to use git wizardry here. If you use branches, they are there to be eventually merged with master or destroyed forever.

Hmm I think I'd be worried about overwriting something in the other project 1's Github by accident. Couldn't I set up a separate Github somehow? i.e.:

  1. Clone Project 1's folder and create 'Project 2',
  2. Delete Project 2's Git and create a new Git,
  3. Carry on from there; everything is completely separate, locally and online (Github); two separate repositories.
Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Yes, you can delete the .git folder inside and do git init again, this will make a fresh git folder with no settings :).

To make sure that no git repo (remote origin) is assigned to it yet, go inside the .git folder and check the config file. Compare the fresh one with the old one. Don't be afraid of exploring mysterious files and folders, git is not as mystical as it seems ;)

Jason Early
Jason Early
52,944 Points

If you are storing your foundation app with the basics you can absolutely just clone it and use it as a new starting point. If you are cloning from a complete app created from someone else you still could, but I'd be worried about building something new on top of it without really understanding how it's set up.

Your 3 steps here are a good approach, just keep the repos separate.