git init command
git init The command is used to create a new Git repository in a directory.
Running git init in a directory creates a Git repository.
After running git init, Git creates a hidden folder named .git in the current directory, which is used to store all the metadata and objects required for version control.
Basic Usage
git init
For example, we create a project named runoob in the current directory:
Example
$
mkdir
runoob
$
cd
runoob
/
$
git init
Initialized empty Git repository
in
/
Users
/
xxx
/
www
/
runoob
/
.git
/
Empty Git repository initialized.
Now you can see that a .git subdirectory has been generated in your project; this is your Git repository, and all content and metadata related to your project are stored here.
After completing the above steps, you have created a new Git repository. You can use other Git commands (such as git add, git commit, etc.) to manage and track your code changes and interact with remote repositories.
Note: The git init command is only used to create a new repository in an empty directory. If you want to clone an existing remote repository locally, please use git clone command.
.git is hidden by default and can be viewed with the ls -a command:
ls -a
. .. .git
Git Basic Operations