Initialize the warehouse

git init
Copy the code

Add all modified files to the staging area

git add .
Copy the code

Add comments and commit the staging contents to the current local branch

git commit -m "xxx"
Copy the code

View the current branch file modification status

git status
Copy the code

Pull remote branch code locally

git pull origin master
Copy the code

The local branch code is pushed to the remote repository

git push origin master
Copy the code

Clone the remote repository locally

By default, a directory with the same name as the remote repository is created under the current path

git clone [email protected]:leexiang59/easy-cli.git
Copy the code

Clone the remote repository to the specified local directory

git clone [email protected]:leexiang59/easy-cli.git newProject
Copy the code

Create local branch A

git branch A
Copy the code

Switch to branch A

git checkout A
Copy the code

or

git switch A
Copy the code

Create and switch to local branch A

git checkout -b A
Copy the code

or

git switch -c A
Copy the code

Merges branch A code into the current branch

git merge A 
Copy the code

Point the current branch’s HEAD to branch A

git rebase A
Copy the code

Deleting a Local Branch

git branch -d xxx
Copy the code

Deleting a Remote Branch

git push origin -d xxx
Copy the code

If it is forcibly deleted, change the -d parameter to -d

View all branches

git branch -a
Copy the code

Renames the current branch name

git branch -m new_branch
Copy the code

Rename the specified branch name

git branch -m old_branch new_branch
Copy the code

Merges the contents of the specified commit record into the current branch

git cherry-pick [commit_id]
Copy the code

Store current fixes

git stash
Copy the code

Viewing the storage list

git stash list
Copy the code

Releases the contents of the last store

git stash pop
Copy the code

Releases the contents specified in the storage list

N is the sequence number of the list

git stash apply [n]
Copy the code

Example Modify the last commit information

git commit --amend
Copy the code

Press I to enter the editing mode. After the modification is complete, press Esc to exit the editing mode and enter :wq. Press Enter to save and exit git push code to the remote repository

Clear the current branch COMMIT information

git checkout --orphan  new_branch
git add .
git commit -m "xxx"
git branch -D master 
git branch -m master
Copy the code

Deletes the remote repository connection for the local project

git remote rm origin 
Copy the code

View the current remote repository

git remote -v
Copy the code

Add a connection between a local project and a remote repository

git remote add origin [email protected]:leexiang59/l-helpers.git
Copy the code

Push code to remote repository for the first time after association

git push -u origin master
Copy the code

View submission History

Git log -3 displays the history of the last three commitsCopy the code

View historical operation commands

git reflog
Copy the code

Discards workspace file modifications

[file] indicates the file name

git checkout -- [file]
Copy the code

Discards all file changes in the workspace

git checkout .
Copy the code

Undo the staging area file modification

git reset HEAD [file]
Copy the code

Undo all file changes in the staging area

git reset HEAD
Copy the code

Rollback to previous version

git reset --hard HEAD^
Copy the code

Rollback to the specified version

Git reset --hardCopy the code

Git tutorial is the easiest Git tutorial ever!

Tools: Git branch practice