内容纲要
概述
将本地已存在的 python 工程 refusea 存储到码云(gitee.com)上
环境
- centos 8.2
工程目录
- /data/python/refusea
安装 git
yum -y install git
安装完成后,查看 git 版本
git --version
git version 2.27.0
配置 git
git config --global user.name 'refusea'
git config --global user.email 'refusea@163.com'
# 查看配置
git config --list
user.name=refusea
user.email=refusea@163.com
配置 gitee 公钥认证
执行下述命令创建密钥,如果 ~/.ssh 下已存在 id_rsa 和 id_rsa.pub,则跳过此步骤
ssh-keygen -t rsa -C "refusea@163.com"
命令执行时输出如下内容,其中 3 次询问,直接回车即可
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:pcuGxPXfEt9z2mI0aMl/ZbDP9edKs/o+yuEKM+0CD+I refusea@163.com
The key's randomart image is:
+---[RSA 3072]----+
| |
| |
| . . |
| . . + . |
| o S ...o o |
| ..oo o .=++.+|
| . ..+B ..+o=**|
| E .o= o +==O|
| .o.=***+|
+----[SHA256]-----+
密钥创建成功后,将公钥添加到 gitee.com(略)
执行下面的命令测试公钥已生效
ssh -T git@gitee.com
The authenticity of host 'gitee.com (180.97.125.228)' can't be established.
ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
Are you sure you want to continue connecting (yes/no/[fingerprint])?
输入 yes
Hi 拒海! You've successfully authenticated, but GITEE.COM does not provide shell access.
公钥认证已配置成功
在 gitee 上创建仓库
仓库名为 refusea
将本地代码推送到 gitee
在工程根目录下执行
cd /data/python/refusea
git init
git remote add origin git@gitee.com:refusea/refusea.git
从远程仓库同步
git pull origin master
warning: Pulling without specifying how to reconcile divergent branches is
discouraged. You can squelch this message by running one of the following
commands sometime before your next pull:
git config pull.rebase false # merge (the default strategy)
git config pull.rebase true # rebase
git config pull.ff only # fast-forward only
You can replace "git config" with "git config --global" to set a default
preference for all repositories. You can also pass --rebase, --no-rebase,
or --ff-only on the command line to override the configured default per
invocation.
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 9 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (9/9), 1.98 KiB | 1.98 MiB/s, done.
From gitee.com:refusea/refusea
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
error: The following untracked working tree files would be overwritten by merge:
.gitignore
Please move or remove them before you merge.
Aborting
拉取不成功,这是因为本地有同名的文件 .gitignore
,可以先删除该文件,待拉取成功后再修改回来
rm .gitignore
rm: remove regular file '.gitignore'? y
这次可以成功同步了
git pull origin master
warning: Pulling without specifying how to reconcile divergent branches is
discouraged. You can squelch this message by running one of the following
commands sometime before your next pull:
git config pull.rebase false # merge (the default strategy)
git config pull.rebase true # rebase
git config pull.ff only # fast-forward only
You can replace "git config" with "git config --global" to set a default
preference for all repositories. You can also pass --rebase, --no-rebase,
or --ff-only on the command line to override the configured default per
invocation.
From gitee.com:refusea/refusea
* branch master -> FETCH_HEAD
将当前目录下所有文件添加到 git 库并提交
git add .
git commit -m 初始导入
推送(首次提交)到 gitee
git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin master
直接 push
失败了根据提示,使用下面命令
git push --set-upstream origin master
Enumerating objects: 79, done.
Counting objects: 100% (79/79), done.
Delta compression using up to 2 threads
Compressing objects: 100% (74/74), done.
Writing objects: 100% (77/77), 42.76 KiB | 6.11 MiB/s, done.
Total 77 (delta 5), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-5.0]
To gitee.com:refusea/refusea.git
77ed942..107eaf6 master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
成功搞定
将本地工程首次提交到 gitee 远程仓库