How to create a new git repository from terminal
To create a new Git repository from the terminal, you can follow these steps:
- Open the terminal and 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 running the command
git init
. This will create a new.git
directory in your current directory and initialize it as a Git repository.git init
- Verify that the repository has been initialized by running the command
git status
. This should show you a message indicating that the repository is empty.git status
- Add all the files in your directory to the Git repository by running the command
git add.
. This will stage all the files in your directory for the next commit.git add.
- Commit the changes by running the command
git commit -m "Initial commit"
. This will create a new commit with the message "Initial commit".git commit -m "Initial commit"
- Verify that the commit has been created by running the command
git log
. This should show you a list of commits, including the initial commit.git log
That's it! You have now created a new Git repository from the terminal.
Here's a summary of the commands:
cd /path/to/new/repo
git init
git status
git add.
git commit -m "Initial commit"
git log
Note: You can also use the --bare
option with git init
to create a bare repository, which is a repository that doesn't have a working directory. This is useful if you want to create a repository that will be used as a remote repository for other projects. For example:
git init --bare
This will create a new bare repository in the current directory.