Common git operations and instructions

1. Instruction set

1.1 Local and remote operation

Create a file

echo> README.md (file name)

Enter information when creating a file

echo “(message)” >> README.md (file name)

Initialize the local warehouse

git init

Add files to the cache stream

git add. (dot "." means to add all files in the current folder, add a file directly using the file name)

Clone a remote warehouse

git clone warehouse address

Put the cache content in the send header

git commit -m "xx" ("xx" is the description of this upload)

​Add remote address

git remote add origin new address

View remote address

git remote -v

Delete remote address

git remote rm origin

Pull remote content

git pull --rebase origin master

Submit to remote

git push (-u) origin branch name (-f) (add -u for the first submission, add -f for forced submission to ignore remote modifications)

1.2 Branch related

New branch

git branch new branch name (SHA value) (if the newly created branch is a copy of a branch, the SHA value must be added, which can be found in git log)

Modify the current branch name

git branch -M main (new branch name) (the difference between -M and -m: the former will be modified even if the new branch name already exists, the latter will not)

Delete branch

git branch -D main (branch name)

View branch status

git status

Switch branch

git checkout branch name

1.3 History related

Allow irrelevant history to be merged

git pull --allow-unrelated-histories

View historical submissions

git log (If the output is':' at the end, press'q' to exit)

2. Common operations

2.1 Initialize the warehouse locally and submit

git init
echo >README.md
git add .//git add README.md
git commit -m "submit README.md"
git remote add origin 仓库地址
git push -u origin master(分支名)

2.2 Modify the remote address

git remote -v
git remote rm origin
git remote add origin 仓库地址

2.3 Switch back to history branch

2.3.1 No branch type

git log
git checkout 分支名

2.3.2 New branch type

git log(记下对应分支的SHA值)
git branch 新分支名 (SHA值)
git checkout 新分支名

Guess you like

Origin blog.csdn.net/qq_45975757/article/details/109264497