Git is one of the most popular version control systems currently. It can help developers better manage code and work together. The following is a comprehensive list of git usage to help you better master git.
First, you need to install git on your computer. You can download the installation package from the official git website (https://git-scm.com/) and install it according to the prompts.
In git, the warehouse is where the code is stored. You can create a new warehouse locally through the following command:
$ git init
A .git folder will appear in this directory, indicating that the local warehouse has been created successfully.
Adding code to the git repository requires two steps, namely adding and submitting.
Add files through the following command:
$ git add filename
Submit files:
$ git commit -m "commit message"
Can be viewed through the following command Warehouse status:
$ git status
Using this command, you can see which files have been modified, which files have been added, etc.
You can view the history of the git warehouse through the following command:
$ git log
This command will list all submitted records, including Submission time, author, submission message, etc.
Sometimes we need to roll back to a previous version, you can use the following command:
$ git reset --hard 版本号
This The command can help us roll back to a previous version. The version number can be obtained through the git log command.
Multiple branches can be created in git. Each branch is independent and can be used to handle different tasks or functions. Create a branch through the following command:
$ git branch 分支名
Switch to the branch:
$ git checkout 分支名
When we complete a certain task, we can merge the branch into the main branch:
$ git merge 分支名
GitHub is a code hosting platform based on Git. You can create public code warehouses for free and share code with developers around the world. You can also use your own team's development in a private way. .
You can create a repository on GitHub, and then push the local code to GitHub:
$ git remote add origin <github repository> $ git push -u origin master
In addition to the above commands , git has many other commonly used commands, such as:
Overall, Git is a very powerful version control system that can help us better manage code. By mastering the above commands, you can use git more efficiently and improve your development level.
The above is the detailed content of Share the usage of git. For more information, please follow other related articles on the PHP Chinese website!