GIT installation and configuration

  • If you use Git for the first time, you can download and install it from the official website

  • After installation, you can right-click on the desktop, and you can find two more options in the right-click menu

  • Click Git Bush Here to go to the command line tool and run our Git command. However, the Git Bush Here command line tool is linux-style and can be used if you prefer to use the Windows command line.

  • When using git for the first time, you need to configure the user name and password, open the command line tool, and perform the following operations:

Git config --global user.name "username" git config --global user.email "***@**.** config user.name git config user.emailCopy the code

When prompted for a password (twice), the entered password will not be displayed.

GIT basic commands

Establish a connection with the remote repository

Git remote add origin [email protected]......Copy the code

Clone the remote repository locally

Git clone [email protected]...Copy the code

Basic commands

Git add. Git commit -m "commit prompt" commit local git repository to git repository git push --force origin master commit git repository to git repository Git branch -r Git branch -r Git check-out -track Git branch name Git checkout -b git checkout -b git push origin --delete branch name git push origin --delete branch name Git branch -d Branch name Delete a local branchCopy the code

Connect the local branch to the remote branch

Git branch -- set-uppage-to =originCopy the code

Multiremote warehouse

To view the linked remote repository, you usually need to run this command by CD to the project folder

Git remote -d git remote -d git remote -d git remoteCopy the code

Add as many new remote repositories as you like. Note that gitee and Origin are custom remote repository names and cannot be duplicated

git remote add gitee [email protected]:xx/xx.git
git remote add origin [email protected]:xx/xx.git
Copy the code

The repository added in the above way has both push and pull capabilities. Therefore, specific repositories need to be specified during push/pull

Git pull repository name Git push repository nameCopy the code

Sometimes, we want to push quickly, i.e. push a command to multiple remote locations simultaneously. To achieve this effect, we need to change the way we add

Git remote set-url --add existing repository name [email protected]:xx/xx.gitCopy the code

Deleting a Remote Connection

Git remote rm User-defined repository nameCopy the code

Q&A

1. You may encounter can not push to the remote warehouse situation (may need to pull), for beginners, here we hand over a simple crude key is useful method!!

git push -f origin master
Copy the code

If you are using VSCode, you can use its git management function by clicking ‘pull from… ‘Update the remote repository contents locally.

2. Cannot be pulled remotely

git pull origin master
Copy the code

or

git push --set-upstream origin master
Copy the code

The second option is to create a branch locally.

Configure SSH connections to GitHub

  1. First, right-click the desktop and open itGit Bash Here Input:
cd ~/.ssh
Copy the code

If no file or directory is found, the SSH key has not been generated and needs to be regenerated.

Otherwise, if you access the directory successfully, the SSH key has been generated and can be used directly.

  1. To create an SSH key, enter:
Ssh-keygen -t rsa -c "Your email name@your email address.com"Copy the code

The red line is the new address where you can find the directory. The purple line is the email address entered earlier.

  1. View the key and type
cat ~/.ssh/id_rsa.pub
Copy the code

Returns the generate key; You can also find the id_rsa.pub file in the directory according to the address in the previous step (red line) and open it with notepad to obtain the key.

  1. Making set up SSH

Go to GitHbub, open the Settings page, find SSH and GPG keys, click the New SSH Key button, paste the SSH key on the key, and save.

  1. For the final step, go back to git bash and type:
Github SSH -t [email protected] // gitee SSH -t [email protected] //PS: If you put your code on Aliyun, you do not need to operate this step.Copy the code

Complete the validation, this step will prompt you to confirm, just type Yes /no and press Enter. If the password is required, enter the password used to configure Git and press Enter.

If you encounter:

You can use your git bound email + email password to log in