Christopher Francisco
Christopher Francisco

Reputation: 16288

Git workflow to start new project from a base repository

I'm not sure if what I'm looking for is also a fork. Basically I have a repository I want to use as a base for all my projects, kind of an skeleton project, a framework with some setup already done.

I thought either cloning or forking would do the job, but the new project is never going to be merged to the base. Is this done through one of those 2, or maybe a different workflow is used?

Upvotes: 1

Views: 554

Answers (2)

Protagonist
Protagonist

Reputation: 502

The easiest way to achieve what you want is to:

  • git clone the base repository to your machine.
  • Delete the .git directory in the newly cloned copy of the base repo on your machine.
  • git init a new repository inside the cloned copy.
  • git remote add origin <remote> inside the cloned copy where <remote> is a URL of repo on Github/BitBucket/others.

The way this works is pretty straightforward.

First, I wanted to explain that clone and fork are very similar in that clone copies a remote repository to your local machine whereas fork is an internal Github/other tool that copies a repository to your account on a given service. Going one level higher, fork is more of an abstract action that is supported by many source control tools even though it rarely exists as a command itself. Using git, you can fork a project by cloning it. So in reality, git clone is really the only answer to your question.

When you clone a repository, you copy all the files in that repository and the .git directory which contains all of the files needed for git to work. This includes all of the project history, all the branch heads, remote urls, and much more.

When you delete the .git directory and run git init inside the project directory, you reset all of the above information to a clean state, and create a fresh .git directory. As far as git is concerned, this is a brand new project. You can start adding files to the index, making commits and branches and work as you normally would. Because the old git information is deleted, git no longer considers this project a part of the base project. Any commits you make here now exist as new repository.

In most cases you also want to add information about a remote repository so you can push your code there and share it with others. This can be a hosted service like Github or you can host it yourself. This, along with the what I wrote in the last paragraph means that when you push, these new commits will be uploaded to a new repository instead of the base repository.

Hope this helps!

Upvotes: 5

Steve Hollasch
Steve Hollasch

Reputation: 2131

First off, clone and fork are synonyms, as far as Git is concerned.

In your case, a simple clone would work, though your new repo would be tied to the skeleton repo. Do you want the skeleton's commit history in projects based on it? Or would you prefer that new projects get the latest version with a completely fresh start?

If you want to preserve history (as if you developed the skeleton and then continued) but sever ties with the skeleton repository, then just clone the project and then 'git remote remove origin' will do that.

If you want to obliterate the skeleton history and just start from the initial set of files, then delete the entire .git directory, and then 'git init' to start fresh.

Upvotes: 1

Related Questions