Create a new repo from the shell git
To create a new repository from the shell using Git, you can follow these steps:
-
Open a terminal or command prompt.
-
Navigate to the directory where you want to create the new repository. You can do this by typing
cd
followed by the path to the directory. For example:cd /path/to/new/repo
-
Initialize a new Git repository by typing the following command:
git init
This will create a new directory called
.git
in the current directory, which will contain the Git repository. -
Add all the files in the directory to the Git repository by typing:
git add.
The dot (
.
) is a wildcard that tells Git to add all files in the current directory and its subdirectories. -
Commit the changes by typing:
git commit -m "Initial commit"
The
-m
option allows you to specify a commit message. In this case, the message is "Initial commit". -
Verify that the repository has been created by typing:
git status
This should show you the status of the repository, including the fact that it's a new repository with no commits.
That's it! You've now created a new Git repository from the shell.
Here's an example of what the output might look like:
$ cd /path/to/new/repo
$ git init
Initialized empty Git repository in /path/to/new/repo/.git/
$ git add.
$ git commit -m "Initial commit"
[master (root-commit) 1234567] Initial commit
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644.gitignore
create mode 100644 README.md
$ git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working directory clean
Note that the git init
command creates a new directory called .git
in the current directory, which contains the Git repository. The git add
and git commit
commands add all the files in the directory to the repository and commit them, respectively. The git status
command shows the status of the repository, including the fact that it's a new repository with no commits.