What is a repository? Repository also known as the Warehouse, English name repository, you can easily understand a directory, all the files in this directory can be managed by git, each file modification, deletion, git can track, so that any time can track history, Or you can "restore" at some point in the future.
Therefore, it is very simple to create a repository, first of all, select a suitable place to create an empty directory:
1 mkdir Learngit 2 CD Learngit 3 pwd
/home/zl/learngi
The PWD is used to display the current directory. Note: This directory is my own, and the pro should not be the same
The second step is to initialize the directory with this command, that is, to turn this directory into a repository that git can manage.
1 git init
Instantly Git has built the warehouse, and tell you is an empty warehouse (empty Git repository), careful readers can find the current directory is a directory of more than one, .git
this directory is git to track the management of the repository, it's OK don't manually modify the directory inside the file , or change the mess, the Git repository to destroy.
If you don't see the .git
directory, it's because the directory is hidden by default and ls -ah
can be seen with commands.
You don't have to create a git repository in an empty directory, and it's also possible to choose a directory that already has something. However, it is not recommended that you use the company project you are developing to learn git, otherwise you will not be responsible for any consequences.
Now, let's write a readme.txt
file that reads:
Git is a version control system. Git is free software.
Be sure to put learngit
it in the directory (subdirectory is also OK), because this is a git repository, put it elsewhere git can not find this file.
It takes 3 steps to put an elephant in the freezer, and it takes only two steps to put a file into a git repository.
The first step is to use the command git add
to tell git to add the file to the repository:
1 git add readme.txt
Execute the above command without any display, that's right, the Unix philosophy is "No news is good news", stating add success.
In the second step, tell git with the command to git commit
submit the file to the repository:
1 " wrote a readme file "
A simple explanation of the git commit
command, followed by the -m
submission of the instructions, you can enter any content, of course, it is desirable to make sense, so that you can easily find changes in the history record.
git commit
When the command executes successfully, it will tell you that 1 files have been changed (our newly added Readme.txt file), inserting two lines of content (Readme.txt has two lines of content).
Why does git need to add files add
in commit
two steps? Because commit
you can submit many files at once, you can have add
different files several times, such as:
git add file1.txt git add file2.txt file3.txt git commit-m "Add 3 files."
Summary:
Now summarize the two things you learned today:
Initialize a git repository, using git init
commands.
Add files to the Git repository in two steps:
The first step, use the command git add <file>
, note, can be used repeatedly, add multiple files;
The second step, using git commit
the command, is done.
Git Tutorials (2)--Create a repository