[Github] git local warehouse establishment and remote connection

foreword

1. Introduction to git

Git is an open source distributed version control system that can effectively and high-speed handle project version management from small to very large.

Two, git download

2.1 Download address

Git client official website download link: https://git-scm.com/downloads
Choose the version that suits your local machine to download.
insert image description here

Three, git installation

3.1 Installation

insert image description here

Double-click "Git-2.17.0-64-bit.exe" to enter the installation guide interface, click Next>
insert image description here

Select the installation path, next>
insert image description here

next>
start menu shortcut directory, the default configuration is enough, click Next>
insert image description here
insert image description here

Select the default editor: Vim, click Next>
select the command line tool, generally choose: User Git from Git Bash only, click Next>
insert image description here

Next all the way next>, until install, the installation is complete.
insert image description here

3.2 configuration

Right click on computer - properties:
insert image description here

To facilitate subsequent applications and verify whether the installation is successful, configure the environment variable to configure the path (this step is optional)
insert image description here

Enter "git --version" in cmd, and if the version information appears, the installation is successful.
insert image description here

3.3 config settings (additions, deletions, modifications, checks)

Set username and email

$ git config --global user.name  "name"//自定义用户名
$ git config --global user.email "[email protected]"//用户邮箱

Revise

git config --global configname configvalue

Inquire

git config --global configname

query all

git config --list

Four. GitHub and git connection - local Git warehouse

4.1 Build a local repository

Equivalent to creating a new empty folder
insert image description here

Enter, right click - Git Bash - enter "git init" to initialize a Git manageable warehouse
insert image description here

At this time, there is an additional .git folder in the folder, which is used by Git to track and manage the repository.
insert image description here

If you can't see it, you need to set it to make hidden files visible.

insert image description here

4.2 Put the source code into the local warehouse

Paste the project/source code into this local Git repository
insert image description here

git status: view the current status

  • Red letters indicate files that have not been added to the Git repository
  • The green word indicates the file that has been added to the Git warehouse

insert image description here

Then add the project/source code to the warehouse through git add
("git add .": add all files in this directory to the warehouse, pay attention to the ".")

It can be seen that the file has turned green after querying the status, indicating that the add is successful

insert image description here

4.3 Submit the warehouse

Submit the project to the warehouse with git commit.
The quotation marks behind -m are the comment content of this submission, which can be omitted, but it is better to write it, otherwise an error will be reported

git commit -m "first commit"

Five, the connection between github and git - remote connection

The transmission between the local Git repository and the GitHub repository is encrypted through SSH, so an ssh key needs to be configured.

5.1 Create SSH Key

In the user's home directory, check whether the ".ssh" file exists.
insert image description here
The local user home directory is the path shown in the figure:

  • If so, check to see if there are two files id_rsa and id_rsa.pub under the file. If so, go directly to the next step.
  • If not, find Git Bash in the starting appendix, enter the command, and create an SSH Key.
    insert image description here
$ ssh-keygen -t rsa -C "[email protected]"

Inside the quotation marks is the email address used for github registration!!

When the three red lines appear, just press Enter.

When viewing .ssh again, there are already "id_rsa", "id_rsa.pub" files.
insert image description here

The secret key pair of SSH Key: id_rsa is the private key and cannot be disclosed; id_rsa.pub is the public key and can be made public.

5.2 Github fill in SSH Key

Open the “Account settings” – “SSH Keys” page
insert image description here

Click "Add SSH Key"
insert image description here

The title is optional, and the key fills in the entire content of id_rsa.pub
insert image description here

5.3 Verification

① Verify whether it is successful, enter the following command in git bash

$ ssh -T [email protected]

②You need to enter yes for the first time setting, and the second red box appears to indicate success.

insert image description here

5.4 GitHub build warehouse

Create a warehouse named "Elegent", do not check initialize here, otherwise an error may be reported later.

insert image description here

5.5 Associate remote warehouse

According to the prompt on the created Git warehouse page (find the prompt code of your own warehouse), you can enter the command line of the local Elegent warehouse:

git remote add origin https://github.com/xu-xiaoya/Elegent.git

1

insert image description here

5.7 Local content upload and push
After the association is completed, we can push all the content of the local library to the remote warehouse (that is, Github), by typing in Bash:

  • Since the newly created remote warehouse is empty, add the -u parameter
    git push -u origin master
  • After the warehouse is not empty, there is no need to add -u
    git push origin master
    The process of uploading the project may take a while...

………………………
Perfect
! A window popped up halfway to let me authorize to log in to github, the problem is not big~
insert image description here

Enter the github warehouse at this time, you can see the newly added files

insert image description here

6. Summary steps and common mistakes

6.1 Steps

  • Initialization: local library (ie folder), git init
  • Add to the warehouse: put the code file into the local library, git add .
  • Submit: git commit -m "comment content", submit to the warehouse
  • Create a new remote warehouse and associate it: After setting up the SSH key on Github, create a new remote warehouse, git remote add origin https://github.com/xu-xiaoya/Elegent.git association
  • Push: git push (-u) origin master, push the code of the local warehouse to the remote warehouse Github

6.2 Common errors (continuously updated)

①Question 1: When creating a new remote warehouse, check Initialize this repository with a README. When pushing, it may report a failed to push some refs to https://github.com/xu-xiaoya/Elegent.git error.

Solution: This is because the README file in your newly created warehouse is not in the local warehouse directory, and the content can be synchronized at this time.

$ git pull --rebase origin master

Then git push origin master will be successful.

Guess you like

Origin blog.csdn.net/u011397981/article/details/132692520