1, first install the GIT software, installation environment is the CentOS 7.x cloud server. Use the command:
# yum install git
2. Set user name and mailbox (required):
# git config--global user.name "Your name" # git config--global user.email "[email protected]"
3, create a repository, choose a suitable place, create an empty directory:
# mkdir learngit #在服务器中创建learngit文件夹
# CD learngit #进入learngit folder
# pwd #显示当前工作路径
Result: (with root user rights)
/root/learngit
4. Initialize this directory as a repository that git can manage, using commands:
# git init in/root/learngit/.git/
The GIT repository has been successfully initialized and is empty, the path is/root/learngit/, and this directory is the repository that git can manage.
5. Add files to the Git repository
# vi read.txt #创建一个文本文件 # i "Hello, World" # Edit File contents
#: X #保存并退出
The first step is to use the command git add
to tell git to add the file to the repository:
# git add read.txt
The second step git commit
is to tell git with a command to submit the file to the repository:
# git commit-m "wrote a read file"
Description: The git commit
command, followed by the -m
instructions for this submission, is a description of the content of the submission of the changes, which makes it easy to find the content of the version update soon.
git commit
Once the command executes successfully, it will tell you that 1 files were changed and 1 lines of content were inserted (Read.txt has 1 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."
Git tutorial under Linux system