Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create a new git repository from a template only using the command line?

Creating a new repo using another as a template is a great function, but I can only see how to use this ability on github.com. Can it be done entirely from command line? Perhaps without a remote?

I would like to use templates for a user to intialise a repo to store their secrets in, and it may not even require a remote, but its very important that it isn't connected to the original template repo for privacy. The .gitignore file and the folder tree provided are the most important functions that I'm hoping to provide the user with this ability.

like image 918
openCivilisation Avatar asked Jun 29 '20 02:06

openCivilisation


People also ask

Can we create git repository from command line?

In the command line, navigate to the root directory of your project. Initialize the local directory as a Git repository. Stage and commit all the files in your project. To create a repository for your project on GitHub, use the gh repo create subcommand.

What command line is used to create a new git repository?

Initializing a new repository: git init To create a new repo, you'll use the git init command.


2 Answers

June 2020: Since a template repository such as this one is a GitHub repository, you can:

  • clone it
  • as commented remove the .git folder
  • git init .
  • git add .
  • git commit -m "First commit"
  • create a new empty repository on GitHub using the new gh CLI: gh repo create
  • git push -u origin master

That way, everything is done form the command line.


Update Sept. 2020: the other approach through the GitHub CLI tool gh, and mentions in Ben Gubler's answer, stems from PR 1590: "Create repositories from a template repo" from Mislav Marohnić and Colin Shum.
(merged in commit 99372f0)

gh repo create <new-repo-name> --template="<link-to-template-repo>"
# OR
gh repo create <new-repo-name> --template="<owner/template-repo>"
like image 119
VonC Avatar answered Nov 10 '22 15:11

VonC


Try gh repo create myrepo --template someuser/sometemplate

like image 11
Ben Gubler Avatar answered Nov 10 '22 15:11

Ben Gubler