Many people think that Git is too messy or a complex version control system. This article is intended for some people who want to quickly get started with Git, for the majority of basic requirements, this article covers the 70%-90% version control systems that many people think Git is too messy or complex. This article is intended for some people who want to quickly get started with Git,
For most basic requirements this article covers 70% to 90%
Getting started
You need to create a repository (repository) before using Git ). You can use an existing directory as a Git repository or create an empty directory.
Use your current directory as the Git repository and we only need to initialize it.
git init
Use the directory we specified as the Git repository
git init newrepo
From now on, we will assume that you are under the Git repository root directory, unless otherwise stated
Add new file
We have a repository, but there is nothing. you can use the add command to add files.
git add filename
You can use add... to add a task file.
Submit version
Now we have added these files, and we hope they can be truly saved in the Git repository,
To this end, we submit them to the warehouse
git commit -m "Adding files"
If you do not use-m, an editor will appear asking you to write your own comments.
When we modify a lot of files, instead of adding each file, we can use the-a identifier to automatically submit local modifications by using commit.
git commit -a -m "Changed some files"
The-a option of the git commit command can only submit all modified or deleted documents that have been managed by git to the warehouse.
Note:-a does not commit new files and can only be modified.
Release version
We first clone a database from the server and upload it.
git clone ssh://example.com/~/www/project.git
After modification, we can push it to the server.
git push ssh://example.com/~/www/project.git
Retrieve updates
If you have followed the above push, the following command indicates that the current branch is automatically merged with the only tracking branch.
git pull
Update from non-default location to specified url
git pull http://git.example.com/project.git
Has it been more than five minutes?
Delete
How do you want to delete files from the resource library, we use rm
git rm file
Branch and merge
Branches are completed locally, and the speed is fast. To create a new branch, run the branch command.
git branch test
The branch command does not bring us into the branch. you only need to create one. Therefore, we use the checkout command to change the branch.
git checkout test
The first branch, or master branch, is called "master ".
git checkout master
However, when you submit a branch, it does not reflect the changes in the main branch. When you do this, or want to submit the changes to the master branch, switch back to the master branch and use merge.
git checkout mastergit merge test
If you want to delete a branch, we use the-d identifier.
git branch -d test