📅  最后修改于: 2023-12-03 14:41:25.776000             🧑  作者: Mango
If you are a programmer, you might have heard of Git - a powerful version control system that allows you to track changes in your code and collaborate with other developers. One of the first things you need to do when starting a new project is to create a new Git repository where you can store your code and keep track of changes over time. In this tutorial, we will show you how to create a new Git repository from scratch using Git commands on the command line.
cd
command to change your current directory. For example, if you want to create a repository in the projects
directory, run the following command: cd ~/projects/
git init
This command will create a new .git
directory in your current directory, which contains all the necessary files for Git to work.
.gitignore
file to tell Git which files or directories to ignore when you commit your changes. echo ".DS_Store" > .gitignore
This command will create a new .gitignore
file in your current directory and add .DS_Store
to the list of ignored files.
README.md
file:echo "# My new repository" > README.md
This command will create a new README.md
file in your current directory and add a header to it.
git add .
This command will stage all the changes you made in your directory, including the newly created files.
git commit -m "Initial commit"
This command will commit your changes to the repository with the message "Initial commit".
Congratulations! You have successfully created a new Git repository from scratch.
Git is a powerful tool for version control and collaboration, and creating a new repository is one of the first steps you need to take when starting a new project. By following the steps outlined in this tutorial, you can easily create a new Git repository from scratch and start tracking your changes today!