使用git + gitee
ubuntu@VM-8-3-ubuntu:~/wuxiang/git$ git --version
git version 2.25.1
ubuntu@VM-8-3-ubuntu:~/wuxiang/git$
ubuntu@VM-8-3-ubuntu:~/wuxiang/git$ git config --global user.name 'wuxxxxx'
ubuntu@VM-8-3-ubuntu:~/wuxiang/git$ git config --global user.email [email protected]
local只对仓库有效
global对登录用户的所有仓库有效
system对系统的所有⽤用户有效
git config --local
git config --global
git config --system
git config --list --local
git config --list --global
git config --list --system
ubuntu@VM-8-3-ubuntu:~/wuxiang/git$ git config --list
user.name=wuxxxxx
user.email=[email protected]
cd 项⽬目代码所在的⽂文件夹
git init
ubuntu@VM-8-3-ubuntu:~/wuxiang/git$ ll
total 8
drwxrwxr-x 2 ubuntu ubuntu 4096 Aug 10 20:13 ./
drwxrwxr-x 5 ubuntu ubuntu 4096 Aug 10 20:13 ../
ubuntu@VM-8-3-ubuntu:~/wuxiang/git$ git init
Initialized empty Git repository in /home/ubuntu/wuxiang/git/.git/
ubuntu@VM-8-3-ubuntu:~/wuxiang/git$ ll
total 12
drwxrwxr-x 3 ubuntu ubuntu 4096 Aug 10 20:22 ./
drwxrwxr-x 5 ubuntu ubuntu 4096 Aug 10 20:13 ../
drwxrwxr-x 7 ubuntu ubuntu 4096 Aug 10 20:22 .git/
ubuntu@VM-8-3-ubuntu:~/wuxiang/git$
cd 某个文件夹
git init your_project #会在当前路路径下创建和项目名称同名的文件夹
cd your_project
ubuntu@VM-8-3-ubuntu:~/wuxiang/git2$ ll
total 8
drwxrwxr-x 2 ubuntu ubuntu 4096 Aug 10 20:24 ./
drwxrwxr-x 6 ubuntu ubuntu 4096 Aug 10 20:24 ../
ubuntu@VM-8-3-ubuntu:~/wuxiang/git2$ git init empty_git_project
Initialized empty Git repository in /home/ubuntu/wuxiang/git2/empty_git_project/.git/
ubuntu@VM-8-3-ubuntu:~/wuxiang/git2$ ll empty_git_project/
total 12
drwxrwxr-x 3 ubuntu ubuntu 4096 Aug 10 20:24 ./
drwxrwxr-x 3 ubuntu ubuntu 4096 Aug 10 20:24 ../
drwxrwxr-x 7 ubuntu ubuntu 4096 Aug 10 20:24 .git/
ubuntu@VM-8-3-ubuntu:~/wuxiang/git2$
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$ ll
total 12
drwxrwxr-x 3 ubuntu ubuntu 4096 Aug 10 20:22 ./
drwxrwxr-x 5 ubuntu ubuntu 4096 Aug 10 20:26 ../
drwxrwxr-x 7 ubuntu ubuntu 4096 Aug 10 20:28 .git/
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$ git config --local user.name 'uuuuu'
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$ git config --local user.email '[email protected]'
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$ git config --local --list
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
user.name=uuuuu
user.email=[email protected]
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$ git config --list
user.name=wuxiang
user.email=[email protected]
pack.windowmemory=32m
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
user.name=uuuuu
user.email=[email protected]
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$
ubuntu@VM-8-3-ubuntu:~$ ssh-keygen -t rsa -C "[email protected]"
(跳出的选项一直回车确认就好)
ubuntu@VM-8-3-ubuntu:~$ cd .ssh/
ubuntu@VM-8-3-ubuntu:~/.ssh$ ls
authorized_keys id_rsa id_rsa.pub known_hosts
ubuntu@VM-8-3-ubuntu:~/.ssh$
拷贝id_rsa.pub文件中的所有内容,复制到如下位置(可以通过主页右上角 「个人设置」->「安全设置」->「SSH 公钥」-> … ,添加生成的 public key(id_rsa.pub) 到当前账户中。)
使用ssh -T 测试,通过的话输出如下内容:
ubuntu@VM-8-3-ubuntu:~/.ssh$ ssh -T [email protected]
Hi wuxiang(@wuxiang16)! You've successfully authenticated, but GITEE.COM does not provide shell access.
ubuntu@VM-8-3-ubuntu:~/.ssh$
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$ git remote add origin [email protected]:wuxiang16/git_learn.git
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$ git remote -v
origin [email protected]:wuxiang16/git_learn.git (fetch)
origin [email protected]:wuxiang16/git_learn.git (push)
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$
由于远程仓库在创建时包含了LICENSE文件,本地仓库包含了Readme文件,两个仓库内容不同步,可以通过如下命令先同步:
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$ git pull origin master --allow-unrelated-histories
From gitee.com:wuxiang16/git_learn
* branch master -> FETCH_HEAD
Merge made by the 'recursive' strategy.
.gitignore | 18 ++++
LICENSE | 674 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 692 insertions(+)
create mode 100644 .gitignore
create mode 100644 LICENSE
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$ ll
total 52
drwxrwxr-x 3 ubuntu ubuntu 4096 Aug 11 11:03 ./
drwxrwxr-x 5 ubuntu ubuntu 4096 Aug 10 20:26 ../
drwxrwxr-x 8 ubuntu ubuntu 4096 Aug 11 11:03 .git/
-rw-rw-r-- 1 ubuntu ubuntu 350 Aug 11 11:03 .gitignore
-rw-rw-r-- 1 ubuntu ubuntu 35147 Aug 11 11:03 LICENSE
-rw-rw-r-- 1 ubuntu ubuntu 0 Aug 10 20:30 Readme
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$ git status
On branch master
nothing to commit, working tree clean
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$
创建几个测试文件,并同步到远程仓库:
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$ ll
total 52
drwxrwxr-x 3 ubuntu ubuntu 4096 Aug 11 11:03 ./
drwxrwxr-x 5 ubuntu ubuntu 4096 Aug 10 20:26 ../
drwxrwxr-x 8 ubuntu ubuntu 4096 Aug 11 11:03 .git/
-rw-rw-r-- 1 ubuntu ubuntu 350 Aug 11 11:03 .gitignore
-rw-rw-r-- 1 ubuntu ubuntu 35147 Aug 11 11:03 LICENSE
-rw-rw-r-- 1 ubuntu ubuntu 0 Aug 10 20:30 Readme
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$ mkdir guojing
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$ touch guojing/xianglongshibazhang.c
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$ mkdir yangguo
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$ touch yangguo/anranxiaohunzhang.c
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$ git add .
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$ git status
On branch master
Changes to be committed:
(use "git restore --staged ..." to unstage)
new file: guojing/xianglongshibazhang.c
new file: yangguo/anranxiaohunzhang.c
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$ git commit -m'add guojing and yangguo'
[master 103b057] add guojing and yangguo
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 guojing/xianglongshibazhang.c
create mode 100644 yangguo/anranxiaohunzhang.c
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$ git push origin master
Enumerating objects: 10, done.
Counting objects: 100% (10/10), done.
Delta compression using up to 2 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (9/9), 873 bytes | 873.00 KiB/s, done.
Total 9 (delta 1), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-6.4]
To gitee.com:wuxiang16/git_learn.git
879782f..103b057 master -> master
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$
本地仓库如下:
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$ tree
.
├── guojing
│ └── xianglongshibazhang.c
├── LICENSE
├── Readme
└── yangguo
└── anranxiaohunzhang.c
2 directories, 4 files
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$