The basic syntax of Git

The basic syntax of Git, suitable for beginners to get started.

Record some basic steps of using Git, suitable for beginners to get started:

  1. Install Git
  • Download and install Git from the official website (https://git-scm.com/).
  • Verify the installation in the command line: git --version.
  1. Configure Git
  • Set the username: git config --global user.name "Your Name".
  • Set the email: git config --global user.email "your_email@example.com".
  1. Create a New Repository
  • Create a new folder: mkdir my_project.
  • Enter the folder: cd my_project.
  • Initialize the repository: git init.
  1. Add Files to the Staging Area
  • Create a file: touch README.md.
  • Add the file: git add README.md.
  • Add all files: git add..
  1. Commit Changes
  • Commit: git commit -m "Initial commit".
  1. Check the Status and History
  • Check the status: git status.
  • View the commit history: git log.
  1. Create and Switch Branches
  • Create a new branch: git branch feature-branch.
  • Switch to the new branch: git checkout feature-branch.
  • Or complete it in one step: git checkout -b feature-branch.
  1. Merge Branches
  • Switch back to the main branch: git checkout main.
  • Merge the branch: git merge feature-branch.
  1. Handle Remote Repositories
  • Add a remote repository: git remote add origin <repository-url>.
  • Push to the remote: git push -u origin main.
  • Pull from the remote: git pull origin main.
  1. Clone an Existing Repository
  • Clone the repository: git clone <repository-url>.
  1. The Method of Emptying a Remote Repository
1 git clone https://github.com/KeL1n1995/KeL1n1995.github.io.git  
2 cd KeL1n1995.github.io  
3 git rm -r *  
4 git commit -m "Clear repository"  
5 git push origin main  
  1. The Method of Updating a Remote Repository
1git init
2git remote set-url origin https://github.com/AniKeLin/Hugo.git
3git add.
4git commit -m "update"
5git push