Git Quick Start Manual_201202

1. Download and install

https://git-scm.com/downloads
network disk download link: https://pan.baidu.com/s/16xpckuEBr7iSLg_0sk-D1Q password: d0uv

2. Initialize the warehouse and make simple configuration

创建项目目录:
$ mkdir learn_git

进入项目目录:
$ cd learn_git

查看目录内容:
$ ls -la
total 24
drwxr-xr-x 1 cdata 197121 0 12月  1 18:07 ./
drwxr-xr-x 1 cdata 197121 0 12月  1 18:07 ../

初始化目录:
$ git init
Initialized empty Git repository in C:/Users/cdata/learn_git/.git/

初始化之后就多了.git目录:
$ ls -al
total 28
drwxr-xr-x 1 cdata 197121 0 12月  1 18:11 ./
drwxr-xr-x 1 cdata 197121 0 12月  1 18:07 ../
drwxr-xr-x 1 cdata 197121 0 12月  1 18:11 .git/

配置仓库的用户和电子邮箱:
$ git config --global user.name "yaoxiaofeng"
$ git config --global user.email "[email protected]"
$ git config --global --list
user.name=yaoxiaofeng
user.email=[email protected]


3. Complete a simplest git operation process: working area, temporary storage area, warehouse

$ clear
$ git status
On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)

现在没有文件要提交,我们可以使用下面的命令来创建文件,也可以使用别的编辑器来编辑一个文件放到git的目录下:
$ pwd
/c/Users/cdata/learn_git

文件放进目录之后,再查看git仓库状态,显示我们刚刚创建的文件处于未追踪状态,并且告诉我们可以使用git add去追踪这个文件:
$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        learn_git.html

nothing added to commit but untracked files present (use "git add" to track)


Then we use git add to convert the files in the workspace to the temporary storage area, and finally use git commit to save the files in the temporary storage area to the git warehouse.

3.1 Understanding of working area, temporary storage area and git warehouse

Work area: The file we modified is first in the work area, at this time the file status is modified.
Temporary storage area: After using git add, the files in the workspace are converted to the temporary storage area. At this time, the files are temporarily stored.
Tip: You can use git add. To temporarily store all modified files in the
git warehouse: use git commit to remove the files from The staging area is moved to the git repository.

4. Sync files in the local warehouse to remote GitHub

After registering a github account, we need to create a warehouse. There are two ways to create a warehouse. One is to create a warehouse from scratch, and the other is to fork someone else's warehouse.

4.1 Create a new warehouse from scratch

  • Click the + sign in the upper right corner

Insert picture description here

  • Create warehouse

Insert picture description here
After the warehouse is created successfully, there will be some hints : It
Insert picture description here
is recommended to use the ssh protocol here, because if you use the https protocol, you may have to enter the github username and password every time when synchronizing the local and remote warehouses. If you use ssh, you only need to be the first Just configure the public and private keys for the second use.

It will also prompt us how to push a local warehouse to a remote warehouse, as follows:
Insert picture description here

  • Configure remote warehouse Configure a remote warehouse
    for our local warehouse. Origin is a name of the remote warehouse. We can customize it. When running this command, it must be in the path of the local warehouse:
git remote add origin [email protected]:yyaoxiaofeng/learn_git.git

Check whether the remote warehouse is successfully configured.

$ git remote
origin
  • Configure public and private keys
$ ssh-keygen.exe -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/cdata/.ssh/id_rsa):
Created directory '/c/Users/cdata/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/cdata/.ssh/id_rsa
Your public key has been saved in /c/Users/cdata/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:PCcTutNXXJ4Ta+YTIv3eQwvAykY2F6j/t4HYRBqWZ+U [email protected]
The key's randomart image is:
+---[RSA 3072]----+
|          .  .   |
|         ...o    |
|        o+.+.Eo  |
|       +.=** o + |
|      . S.*.* O  |
|       o X+o.B + |
|      o o.oo .* .|
|       . . . o.= |
|            ..o o|
+----[SHA256]-----+

Switch to the public key directory, use cat to view the public key, then copy the content of the public key, switch to the github page, and click settings.

$ cd /c/Users/cdata/.ssh/

$ ls
id_rsa  id_rsa.pub

$ cat id_rsa.pub

Insert picture description here
Paste the key we copied in Add SSH key.
Insert picture description here
Test whether the local and remote github can establish a connection:

$ ssh -T [email protected]
The authenticity of host 'github.com (198.19.13.19)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,198.19.13.19' (RSA) to the list of known hosts.
Hi yyaoxiaofeng! You've successfully authenticated, but GitHub does not provide shell access.

Switch back to our github warehouse after successful verification:

$ cd learn_git/

$ pwd
/c/Users/cdata/learn_git

Push the local warehouse to the github warehouse:

$ git push -u origin master
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 223 bytes | 44.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:yyaoxiaofeng/learn_git.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

Verify whether the push is successful

Summary of the new warehouse submission process :
1. Modify local files
2.git add learn_git.html
3.git commit -m “web3.0”
4.git push -u origin master

4.2 Fork someone else's warehouse

Process :

  • First fork this repository to your GitHub account.
  • Clone the warehouse after the fork
    to the local, and then create or modify your own code work in the directory of the corresponding week in the local warehouse. The study summary of the week is written in the README.md file of the corresponding week.
  • After finishing the job in the local warehouse, push to your own GitHub remote warehouse.
  • Finally, the link to the current week’s homework in the remote warehouse is posted under the issue of the corresponding learning week in the class warehouse according to the format.
    The first step: fork
    Insert picture description here
    what is fork : it
    is to copy a copy of someone else's github repository to your own github account, but the two repositories are independent, that is, after one is modified, the other is not modified.

After fork, the username becomes my current login username, and it also shows where the warehouse fork is from.
Insert picture description here
Step 2: Clone to a
good local fork warehouse, you cannot edit it directly on the web page, but you need to colo to the local, and then push to the github remote warehouse after the local editing is done.
Insert picture description here
Be careful not to run the git clone command in an existing git repository .

Execute the clone command :

$ pwd
/c/Users/cdata
$ git clone [email protected]:yyaoxiaofeng/algorithm021.git
Cloning into 'algorithm021'...
Warning: Permanently added the RSA host key for IP address '192.30.255.113' to the list of known hosts.
remote: Enumerating objects: 13, done.
remote: Counting objects: 100% (13/13), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 13 (delta 2), reused 1 (delta 0), pack-reused 0
Receiving objects: 100% (13/13), done.
Resolving deltas: 100% (2/2), done.

Enter the cloned directory to check which files are there :

$ cd algorithm021/

cdata@DESKTOP-3533HED MINGW64 ~/algorithm021 (main)
$ ls
README.md  Week_02/  Week_04/  Week_06/  Week_08/  Week_毕业总结/
Week_01/   Week_03/  Week_05/  Week_07/  Week_09/

cdata@DESKTOP-3533HED MINGW64 ~/algorithm021 (main)
$ ls -l
total 4
-rw-r--r-- 1 cdata 197121 1284 12月  2 09:56 README.md
drwxr-xr-x 1 cdata 197121    0 12月  2 09:56 Week_01/
drwxr-xr-x 1 cdata 197121    0 12月  2 09:56 Week_02/
drwxr-xr-x 1 cdata 197121    0 12月  2 09:56 Week_03/
drwxr-xr-x 1 cdata 197121    0 12月  2 09:56 Week_04/
drwxr-xr-x 1 cdata 197121    0 12月  2 09:56 Week_05/
drwxr-xr-x 1 cdata 197121    0 12月  2 09:56 Week_06/
drwxr-xr-x 1 cdata 197121    0 12月  2 09:56 Week_07/
drwxr-xr-x 1 cdata 197121    0 12月  2 09:56 Week_08/
drwxr-xr-x 1 cdata 197121    0 12月  2 09:56 Week_09/
drwxr-xr-x 1 cdata 197121    0 12月  2 09:56 Week_毕业总结/

Test submission function :
modify some files first, then add, commit

$ git add .

cdata@DESKTOP-3533HED MINGW64 ~/algorithm021 (main)
$ git commit -m "week01作业"

Push to remote warehouse :

git push -u origin main
或者:
git push -u origin master

Note: The premise is that you have set up the public and private keys of the ssh of this warehouse, and the method is the same as the method in the previous chapter.

Then you can find the pushed files in the remote warehouse. Finally, copy the file link to the job path. In fact, it can be an open source project's issues. If the code is well written, it can be adopted by the project manager.

Guess you like

Origin blog.csdn.net/a18829292719/article/details/110442407