Home >Development Tools >git >Share the usage of git

Share the usage of git

PHPz
PHPzOriginal
2023-04-10 09:03:10773browse

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.

  1. Install 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.

  1. Create a warehouse

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.

  1. Add and submit files

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"
  1. View the status of the warehouse

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.

  1. View history

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.

  1. Rollback to a certain version

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.

  1. Branch Management

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 分支名
  1. Use github

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
  1. Other commands

In addition to the above commands , git has many other commonly used commands, such as:

  • git diff: compare the differences between two versions;
  • git clone: ​​clone a remote warehouse to the local;
  • git pull: update the code from the remote repository to the local one;
  • git push: push the local code to the remote repository.

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn