Git introduction and basic usage

Git is a distributed version control system widely used in team collaboration development and version management. This article will introduce the basic usage of Git, including initializing the warehouse, adding files, submitting changes, pushing to remote warehouses, etc.

  1. Initialize the Git warehouse In the project directory to be version controlled, use the following command to initialize the Git warehouse:

    git init
    
  2. Add files To add files in the project to the staging area of ​​the Git repository, use the following command:

    git add <file>
    

    For example, add index.htmla file named:

    git add index.html
    
  3. Commit changes Submit the files in the temporary storage area to the Git repository, use the following command:

    git commit -m "commit message"

    For example, submit and add a description:

    git commit -m "Add index.html file"
  4. View warehouse status You can use the following command to view the status of the warehouse, including modified files and untracked files, etc.:

    git status
  5. The remote warehouse associates the local warehouse with the remote warehouse for push and pull operations. First, add the URL of the remote repository:

    git remote add origin <remote_url>

    For example, to add origina remote repository named:

    git remote add origin https://github.com/user/repo.git

    Then, push the local commits to the remote repository:

    git push -u origin master
  6. Updates and pulls In multi-person collaborative development, other people may have made updates to the repository. You can use the following command to pull the latest code from the remote warehouse to the local:

    git pull origin master

The above is a brief introduction to the basic usage of Git, covering common operations such as initializing the warehouse, adding files, submitting changes, pushing to remote warehouses, and updating and pulling. By mastering these basic commands, you can start using Git for version control and collaborative team development.

Guess you like

Origin blog.csdn.net/weixin_42279822/article/details/131128416