[How to use Git commands to create projects on Gitee under Linux]

Table of contents

1 Create warehouse

2 Git submits three tricks

 2.1 add

 2.2 commit

2.3 push


1 Create warehouse

First of all, we can use the command: git --version to check whether it is downloaded to git. If it is not downloaded, we can use the following command to install it:

sudo yum install -y git

After success, you can view:

[grm@VM-8-12-centos lesson4]$ git --version
git version 1.8.3.1

We first open the Gitee website, create a new warehouse, and click the clone on the right after it is created:

 Then you can set it as open source.

 Then copy and paste the code you just cloned into the specified place below:

 Then you will be prompted to enter the user name and password, and you can enter it correctly according to the prompts. If you display the current directory in ll, you will find an additional Linux_cpp warehouse, and then we enter the warehouse:

[grm@VM-8-12-centos ~]$ ll
total 24
-rw-rw-r-- 1 grm grm  827 Jan  3 13:15 install.sh
drwxrwxr-x 2 grm grm 4096 Jan  3 13:11 lesson1
drwxrwxr-x 2 grm grm 4096 Jan  4 16:39 lesson2
drwxrwxr-x 2 grm grm 4096 Jan  4 22:14 lesson3
drwxrwxr-x 2 grm grm 4096 Jan  8 20:30 lesson4
drwxrwxr-x 3 grm grm 4096 Jan  9 21:57 linux_cpp
[grm@VM-8-12-centos ~]$ cd linux_cpp
[grm@VM-8-12-centos linux_cpp]$ ls -la
total 36
drwxrwxr-x  3 grm grm 4096 Jan  9 21:57 .
drwx------ 13 grm grm 4096 Jan  9 21:57 ..
drwxrwxr-x  8 grm grm 4096 Jan  9 21:57 .git
-rw-rw-r--  1 grm grm  270 Jan  9 21:57 .gitignore
-rw-rw-r--  1 grm grm 9592 Jan  9 21:57 LICENSE
-rw-rw-r--  1 grm grm  830 Jan  9 21:57 README.en.md
-rw-rw-r--  1 grm grm  919 Jan  9 21:57 README.md

We will be able to see a directory named .git, and this directory is our code warehouse. We can copy the files we want to submit to this directory, and then perform the three tricks of Git submission.


2 Git submits three tricks

We first copy the files we want to the .git directory:

[grm@VM-8-12-centos lesson4]$ cp -rf probar.c ../linux_cpp

 2.1 add

[grm@VM-8-12-centos linux_cpp]$ ls -la
total 40
drwxrwxr-x  3 grm grm 4096 Jan  9 21:59 .
drwx------ 13 grm grm 4096 Jan  9 21:57 ..
drwxrwxr-x  8 grm grm 4096 Jan  9 21:57 .git
-rw-rw-r--  1 grm grm  270 Jan  9 21:57 .gitignore
-rw-rw-r--  1 grm grm 9592 Jan  9 21:57 LICENSE
-rw-rw-r--  1 grm grm  310 Jan  9 21:59 probar.c
-rw-rw-r--  1 grm grm  830 Jan  9 21:57 README.en.md
-rw-rw-r--  1 grm grm  919 Jan  9 21:57 README.md
[grm@VM-8-12-centos linux_cpp]$ git add probar.c
git add [ filename ]

 2.2 commit

When we run the following program:

[grm@VM-8-12-centos linux_cpp]$ git commit -m "进度条"

Among them, -m " " is the log information that must be written, and it is best to write something meaningful instead of scribbling.

[grm@VM-8-12-centos linux_cpp]$ git commit -m "进度条"
[master a895c89] 进度条
 1 file changed, 18 insertions(+)
 create mode 100644 probar.c

 Next, if your Gitee is not bound to your email address and user, the operating system will remind you to bind it. In this city, you only need to copy and paste the two lines of code below Run, and change your email address and user name.

  git config --global user.email "[email protected]"
  git config --global user.name "Your Name"

Then you can use git log to view:

[grm@VM-8-12-centos linux_cpp]$ git commit -m "进度条"
[master 973f7a3] 进度条
 1 file changed, 18 insertions(+)
 create mode 100644 probar.c
[grm@VM-8-12-centos linux_cpp]$ git log
commit 973f7a33c12840698867262964725d82fca4f387
Author: MONDAY SKY <[email protected]>
Date:   Mon Jan 9 21:20:06 2023 +0800

    进度条

commit b92bdc51a682959a8af2deb707995d2e17c8414f
Author: MONDAY SKY <[email protected]>
Date:   Sun Jan 8 12:11:29 2023 +0000

    Initial commit

2.3 push

Use the command:

git push

Then enter your bound phone number and password and you're good to go!

[grm@VM-8-12-centos linux_cpp]$ git push
Username for 'https://gitee.com': 17828872725
Password for 'https://[email protected]': 
Counting objects: 8, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 3.39 KiB | 0 bytes/s, done.
Total 7 (delta 3), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/monday-sky/linux_cpp.git
   ba0aff3..4780e19  master -> master

Then open Gitee to see the code we submitted:

Guess you like

Origin blog.csdn.net/m0_68872612/article/details/128604996