git detailed use


First, check whether you have generated it before:

cd ~/.ssh

If you can enter the .ssh file directory, it proves that the .ssh key has been generated before, and the secret key in it can be used directly.

1. If it has not been configured before
1. Configure
$ git config --global user.name "username"

$ ​​git config --global user.email "mail"

git config --list View the set configuration

2. Generate the secret key
ssh -keygen -t rsa -C 'The mailbox above'

Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Mr.Yang/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Mr.Yang/.ssh/id_rsa.
Your public key has been saved in /c/Users/Mr.Yang/.ssh/id_rsa.pub .
The key fingerprint is:
SHA256:zA6wNJrFB6NcqS6eBog/AHlzQuvFjYpG759Yhh1lWGI [email protected] (the above email address)
The key's randomart image is:
+---[RSA 2048]----+
| +E . |
| ..+oo+ |
| oo+*+ .o |
|o.*===+o |
|==+*... S |
|B.+.o .o |
|++o. + . |
| +o.+ . |
|. oo |
+----[SHA256]-----+
C drive will generate .ssh folder with public key and key
C:\Users\Users\.ssh C:\Users\Public\Nwt


due to Clone It is transmitted through SSH, so you need to generate the authentication information of your machine, generate the SSH authentication information, enter the following code, and press Enter all the way:
juwankui@ubuntu:~/workspace$ ssh-keygen -t rsa -b 4096 -C youremail@ After example.com
is completed, go to the file where the key is stored:
cat ~/.ssh/id_rsa.pub
Copy the public key and put it on GitHub – setting – SSH and GPG keys
to start Clone, confirm the project storage location before cloning, and enter the corresponding directory:
juwankui@ubuntu:~/workspace$ git clone [email protected]:wankuiju/hello -world.git
will prompt the following information when cloning, enter yes,

after the project is cloned, the project folder will be created automatically, we now go to the project directory:
cd hello-world


git init (initialize the local library)

git add * or git add file name (add a folder or file)

git status (view the status of the working directory and staging area)

often encounter one less that is not added
git add .htaccess

git status (view the status of the working directory and staging area)

git commit -m "The name of the remote warehouse created by yourself" Submit the things in the staging area to the repository (remote repository)

git push -u Repository (remote repository) master Push





the name of the branch created by git branch Create the name of the branch created by

git checkout Switching branches





often encounter this error, this error is that push was rejected
The reason is that different developers have modified the same part of the same file. At this time, conflicts will occur.
$ git push -u [email protected]:yangzong1998/zheng.git master
Counting objects: 31, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (25/25), done.
Writing objects: 100% (31/31), 9.85 KiB | 325.00 KiB/s, done.
Total 31 (delta 0), reused 0 (delta 0)
To github.com:yangzong1998/zheng.git
 * [new branch] master -> master
Branch ' master' set up to track remote branch 'master' from '[email protected]:yangzong1998/zheng.git'.




If there is no version working directory and no .git hidden file, an error will be reported, showing that there is no such repository Not a git repository ( or any of the parent directories): .git

git add Submit a local file, submit multiple add *

The git status command is used to display the status of the working directory and staging area. Use this command to see which changes are staged, which are not, and which files are not tracked by Git. git status does not show information that has been committed to the project history. To see the information of the project history, use git log

and then git -m commit to submit the contents of the staging area to the repository, and then use git push -u to push the repository (remote repository address) master


to create a working directory first, and then add files to Staging area, then submit these files to the repository (local repository), and then submit them to the remote repository,



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325847772&siteId=291194637