Common Commands
git init
Initialize the repository.
git status
View the current status of the repository.
git add
Add files to the staging area.
1 2 3 4 5
| # Add the specified file git add <file_name> # Add all files git add .
|
git commit
Commit the staging area to the local repository.
1
| git commit -m "Commit message"
|
git log
View submission history.
1 2
| git log git log --all --graph --decorate
|
git reset
Undo the changes.
- Revert the most recent commit
- Fallback to a specific version
1
| git reset --hard <commit_id>
|
git diff
Compare the workspace with the staging area.
git checkout
- Switch from the current branch to the specified branch
1
| git checkout <branch_name>
|
For example, switch the working directory to the main branch:
- Create a new branch and switch to this new branch immediately
1
| git checkout -b <new-branch-name>
|
git branch
1
| git branch -d <branch_name>
|
git merge
Merge other branches into the current working branch.
git merge <branch_to_merge>
For example, merge the modifications of the dev branch into the current branch:
git push
Push the local branch to the remote.
1
| git push origin <local_branch>
|
git pull
Pull the remote branch.
1
| git pull origin <remote_branch>
|
git tag
1
| git push origin <tag_name>
|
Reference Links