Abstract: Introduction Before using Git, you need to set up a warehouse (repository). You can use an existing directory as a Git repositor...
Introduction
Before using Git, you need to set up a warehouse (repository). You can use an existing directory as a Git repository or create an empty directory. Using your current directory as the Git repository, we just 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 in the root directory of the Git repository, unless otherwise noted.
Add a new file
We have a warehouse, and we can use the add command to add files.
Git add filename
You can use add... continue to add task files.
Submit version
Now that we have added these files, we want them to be actually stored in the Git repository. To do this, we submit them to the warehouse.
Git commit-m "Adding files"
If you do not use-m, an editor will appear to allow you to write your own comments. When we modify a lot of files and don't want every one of them to add, if you want commit to automatically submit local changes, we can use the-a flag.
Git commit-a-m "Changed some files"
The-an option of the git commit command submits all documents that have been modified or deleted and have been managed by git to the repository. Please note that-a will not cause new documents to be submitted, but can only be modified.
Release version
Let's clone a library from the server and upload it.
Git clone ssh://example.com/~/www/project.git
Now we can push it to the server after we modify it.
Git push ssh://example.com/~/www/project.git
Retrieve updates
If you have push as above, the following command indicates the current branch is automatically merged with the only tracking branch.
Git pull
Updates from a non-default location to the specified url.
Git pull http://git.example.com/project.git
It's been more than five minutes?
Delete
If you want to delete files from the repository, we use rm.
Git rm file
Branching and merging
The branch is completed locally and is fast. To create a new branch, we use the branch command.
Git branch test
The branch command doesn't take us to the branch, it just creates a new branch. So we use the checkout command to change the branch.
Git checkout test
The first branch, or main branch, which is called "master".
Git checkout master
Changes to other branches are not reflected on the primary branch. If you want to commit changes to the main branch, you need to switch back to the master branch and then use merge.
Git checkout master Git merge test
If you want to delete the branch, we use the-d flag.
Git branch-d test