Using git to create a template project for repeated use

twitter logo github logo ・1 min read

I am fairly good at using git, but I need some help setting up a pattern to make it easy to build a base project, that I can clone and then make into it's own project for reuse.

I've researched quite a bit but no real clear answer on this other than doing a clone followed by removing the .git folder.

I feel there has to be a better way.

twitter logo DISCUSS (8)
markdown guide
 

Why not just clone the repo and delete the origin remote and push to a new remote that will be the actual project repo. Assuming you have template.git with the template and project.git as a bare repo:

$ git clone .../template.git project-name
$ cd project-name
$ git remote remove origin
$ git remote add origin .../project.git
$ git push origin master -u
 

Depends on what do you mean by a "base project".

If you want to have a certain file structure covered, just git init then init an application template with whatever your stack is (something like npm init).

Or have the folder/file tree ready somewhere else and wrap it into a shell alias cp -r /home/templates/stuff/* . (also a cool opportunity to extend it to the function that inits your base project depending on an argument).

If you want to have a blank project with a remote ready to go, you can also either use hub or create a new, let's say, GitHub repo with curl -u 'username' https://api.github.com/user/repos -d '{"name":"my repository name"}'. Github API can be very handy. Can also be wrapped in a function.

There is so much stuff!

 

I think github currently has a feature which enables a dev to use a repo as a template for his other repo/projects.

 

Yes. I was hoping there’s an API we can use for this one but as of the time of writing, I can’t find it.

Spoke too soon, here it is folks: developer.github.com/v4/mutation/c...

 

sweet! i'll have to take a look. Thank you

 

Why not write a custom bash command?

or

From my understanding git deletes 'headless' branches, so rather than deleting .git/, you can just delete the branches and start a new branch & head. The old ones should just wither away, along with the data. Git man page says after 30 days it deletes that stuff.

 

So I actually write quite a few bash scripts, enough where I keep a repo of them. I just was really hoping that git, has a native command.

 

Most frameworks create a CLI script that downloads the zip version of the repo, extract it in the specified directory and run needed commands ( git init, npm install, etc )

Classic DEV Post from Aug 6

What to put in your portfolio as a beginner web dev

DeChamp profile image
Just a coder and a dad. I love my family and I love to code!!!! started coding at 11, so I have 25 years under my belt. Still love learning about it every day. Follow me on instagram @codeFiend

Sore eyes?

dev.to now has dark mode.

Go to the "misc" section of your settings and select night theme ❤️