Record some basic steps of using Git, suitable for beginners to get started:
- Install Git
- Download and install Git from the official website (https://git-scm.com/).
- Verify the installation in the command line:
git --version
.
- Configure Git
- Set the username:
git config --global user.name "Your Name"
. - Set the email:
git config --global user.email "your_email@example.com"
.
- Create a New Repository
- Create a new folder:
mkdir my_project
. - Enter the folder:
cd my_project
. - Initialize the repository:
git init
.
- Add Files to the Staging Area
- Create a file:
touch README.md
. - Add the file:
git add README.md
. - Add all files:
git add.
.
- Commit Changes
- Commit:
git commit -m "Initial commit"
.
- Check the Status and History
- Check the status:
git status
. - View the commit history:
git log
.
- 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
.
- Merge Branches
- Switch back to the main branch:
git checkout main
. - Merge the branch:
git merge feature-branch
.
- 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
.
- Clone an Existing Repository
- Clone the repository:
git clone <repository-url>
.
- 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
- 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