Git common commands and operations

91. Git常用命令及操作

Git is one of the most used and popular tools when it comes to version control systems. Below are examples and brief introductions of some commonly used Git commands and operations.

1. Initialize a Git repository:

$ git init

This command creates a new Git repository in the current directory.

2. Clone the remote warehouse to the local:

$ git clone <remote_url>

Use this command to clone the remote warehouse to the local.

3. Add files to the staging area:

$ git add <file_name>

This command adds the specified file to Git's staging area, ready for submission.

4. Commit your changes:

$ git commit -m "commit message"

Use this command to commit the changes in the staging area to the local repository with a commit message.

5. Push to the remote warehouse:

$ git push origin <branch_name>

Push the commits from the local repository to the remote repository.

6. Pull remote updates:

$ git pull origin <branch_name>

Use this command to pull the latest updates from the remote warehouse to the local.

7. Create a new branch:

$ git branch <branch_name>

Use this command to create a new branch.

8. Switch branches:

$ git checkout <branch_name>

Switch to the specified branch.

9. Merge branch:

$ git merge <branch_name>

Merge changes from the specified branch into the current branch.

10. Check status:

$ git status

This command is used to view the status of the current repository, showing uncommitted changes.

This is just a sample of some commonly used commands in Git. Version control with Git also involves many other commands and operations, such as branch management, tag management, undoing changes, and more.

Guess you like

Origin blog.csdn.net/weixin_42560424/article/details/131429963