00 - 环境配置

1. 环境说明

使用git + gitee

2. 安装配置

bash 复制代码
ubuntu@VM-8-3-ubuntu:~/wuxiang/git$ git --version
git version 2.25.1
ubuntu@VM-8-3-ubuntu:~/wuxiang/git$

2.1 配置user信息

bash 复制代码
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 156xxxx5802@163.com

2.2 config的三个作用域

local只对仓库有效

global对登录用户的所有仓库有效

system对系统的所有⽤用户有效

bash 复制代码
git config --local
git config --global
git config --system
  • 显示config的作用域,加list
bash 复制代码
git config --list --local
git config --list --global
git config --list --system
bash 复制代码
ubuntu@VM-8-3-ubuntu:~/wuxiang/git$ git config --list
user.name=wuxxxxx
user.email=156xxxx5802@163.com

3. 建git仓库

3.1 把已有的项目代码纳入git管理

bash 复制代码
cd 项⽬目代码所在的⽂文件夹
git init
bash 复制代码
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$

3.2 新建的项目直接用git管理

bash 复制代码
cd 某个文件夹
git init your_project #会在当前路路径下创建和项目名称同名的文件夹
cd your_project
bash 复制代码
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$

3.3 配置local的user和email

bash 复制代码
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 '156xxxx5802@163.com'
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=156xxxx5802@163.com
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$ git config --list
user.name=wuxiang
user.email=156xxxx5802@163.com
pack.windowmemory=32m
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
user.name=uuuuu
user.email=156xxxx5802@163.com
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$

3.4 优先级:local > global > system


4. 远程仓库配置


bash 复制代码
ubuntu@VM-8-3-ubuntu:~$ ssh-keygen -t rsa -C "156xxxx5802@163.com"
(跳出的选项一直回车确认就好)
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 测试,通过的话输出如下内容:

bash 复制代码
ubuntu@VM-8-3-ubuntu:~/.ssh$ ssh -T git@gitee.com
Hi wuxiang(@wuxiang16)! You've successfully authenticated, but GITEE.COM does not provide shell access.
ubuntu@VM-8-3-ubuntu:~/.ssh$

关联远程仓库:

bash 复制代码
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$ git remote add origin git@gitee.com:wuxiang16/git_learn.git
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$ git remote -v
origin  git@gitee.com:wuxiang16/git_learn.git (fetch)
origin  git@gitee.com:wuxiang16/git_learn.git (push)
ubuntu@VM-8-3-ubuntu:~/wuxiang/git_learn$

由于远程仓库在创建时包含了LICENSE文件,本地仓库包含了Readme文件,两个仓库内容不同步,可以通过如下命令先同步:

bash 复制代码
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$

5. 往仓库里添加文件并同步到远程仓库

创建几个测试文件,并同步到远程仓库:

bash 复制代码
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 <file>..." 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$

本地仓库如下:

bash 复制代码
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$

远程仓库如下:

相关推荐
yyycqupt4 小时前
git使用(一)
git
Kkooe8 小时前
GitLab|数据迁移
运维·服务器·git
Beekeeper&&P...9 小时前
git bash是什么,git是什么,git中的暂存区是什么,git中的本地仓库是什么,git中工作目录指的是什么
开发语言·git·bash
兰琛12 小时前
20241121 android中树结构列表(使用recyclerView实现)
android·gitee
Stara051113 小时前
Git推送+拉去+uwsgi+Nginx服务器部署项目
git·python·mysql·nginx·gitee·github·uwsgi
坐公交也用券13 小时前
使用Python3实现Gitee码云自动化发布
运维·gitee·自动化
lsswear14 小时前
GIT 操作
git
勋勋勋勋小勋勋14 小时前
git分支合并某一次提交
git
PandaCave15 小时前
git常用命令以及注意事项总结
git