git basic command (a set of processes)

ps: for personal use

git process

1. Create a new folder

2. Initialize local library

git init
be careful!!!
Remember to change the name of each new project
git config --local user.name "name"
git config --local user.email "email"

3. Establish remote library connection

git remote add origin +address

3.1. If: error: remote origin already exists

3.2. Delete the remote library first

git remote rm origin

3.3. Re establish connection

git remote add origin +address

4. Pull branch (without adding the remote branch name, the default is to pull the master, download the code of the remote warehouse to the local branch and merge quickly)

git pull origin +Remote branch name

5. Clone warehouse

Directly pull and check out to local

git clone -b +branch + address
git clone +Address (default clone) master Branch)
be careful!!!
Remember to change the name of each new project
git config --local user.name "name"
git config --local user.email "email"
There may be no corresponding connection after cloning
It can be seen from the following 4. If the connection is not established by using 4.1

git related operations

1. View all branches, including local and remote

git branch -a

2. View remote branches

git branch -r

3. View local branches

git branch

4. You can view the remote branch corresponding to the local branch

git branch -vv

4.1 connection between local branch and remote branch

# Establish a connection between the local branch master and the remote branch master
git branch --set-upstream-to=origin/master master

5. Switch branch

git checkout Branch name

6. Create a branch and switch. If yes, switch to master.

git checkout -b master

7. Rename branch

7.1. Local branch renaming (not pushed to remote)

git branch -m oldName newName

7.2. Remote branch renaming (remote has been pushed - assuming that the local branch and the remote corresponding branch have the same name)

7.2.1 rename the local branch corresponding to the remote branch

git branch -m oldName newName

7.2.2. Delete remote branch

git push --delete origin oldName

7.2.3. Upload the newly named local branch

git push origin newName

8. Switch branch to master

git checkout master

9. Merge branches (merge A to B)

9.1. Switch to branch B first

git checkout B

9.2. Merge branch A

git merge A

10. Delete branch

(Note: the currently used branch cannot be deleted, otherwise: error: Cannot delete branch 'xxx' checked out at 'xxx')
git branch -d branchname

11. Upload local modifications to remote warehouse

11.1. View local modification

git status
The specific status is as follows:
Untracked: Not tracked,Generally, it is a new file, which is in the folder, But did not join git library, Do not participate in version control. adopt git add The status changes to Staged
Modified: File modified, Just modify, No other operations were performed
deleted:  The file has been deleted, deleted locally, and not deleted on the server
renamed: File rename

11.2. Submit the files in the work area to the temporary storage area. For specific commands of git add, please refer to:

Commit state changed code to cache
git add .            # Add all modified codes in the current directory from the workspace to the staging area. Represents the current directory
git add <file>       # Adds the specified file from the workspace to the staging area

11.3. Submit the files in the staging area to the local library

git commit -m 'commit message'  # Add cache content to local library

11.4. Upload local database to remote database

git push                    # Upload local library code
git push origin <branch>    # Upload the contents of the local warehouse to the specified remote branch and merge quickly

git commit --amend modify the last commit

git cherry-pick  commitID     # Merge a submission to the current branch
git log --author="name"       # View someone's modification submission

About git user name and address (permanently modified)

1. View user name and address

git config user.name
git config user.email

2. Modify user name and address

#  Method 1: Command modification
git config --global user.name "your name"
git config --global user.email "your email"

#  Method 2: modify the configuration file
vi ~/.gitconfig

Quick look-up table of git common commands

**

Keywords: git

Added by Greaser9780 on Fri, 17 Sep 2021 12:19:55 +0300