您现在的位置是:亿华云 > 应用开发

手把手教你如何上传代码到Gitee服务器

亿华云2025-10-09 13:56:20【应用开发】4人已围观

简介​​之前编写了几个适合新手的小项目, 为方便大家学习和下载代码, 决定把代码上传到gitee服务器。不得不说,git是一个非常好用的代码版本管理工具,本文手把手教大家如何将自己编写的代码上传到Gite

之前编写了几个适合新手的手把手教小项目, 为方便大家学习和下载代码,何上 决定把代码上传到gitee服务器。传代

不得不说,手把手教git是何上一个非常好用的代码版本管理工具,本文手把手教大家如何将自己编写的传代代码上传到Gitee。

1. 注册账号

打开网页

复制https://gitee.com/1.

点击注册,手把手教 输入一个自己喜欢的何上域名,yikoulinux输入手机号,传代验证即可

点击注册并绑定 即可。手把手教

2.绑定微信

点击头像->设置

然后会弹出二维码,何上 用自己的传代微信扫描二维码即可。

3. 绑定邮箱

后续版本管理操作需要绑定邮箱才能继续操作。手把手教

点击头像->设置

点击 左边邮箱管理->新增然后输入刚才设置的何上gitee登录密码

正确会进入下面页面, 输入自己的传代邮箱(一口君用的QQ邮箱)

点击确定

然后登录自己邮箱,点击对应的服务器托管链接即可。

4. 新建仓库

点击头像左侧的+ -> 新建仓库

输入名称以及开源许可证等。

点击创建即可。

5. clone克隆仓库到本地

复制仓库链接:

进入ubuntu 如果没有安装git,可以执行以下命令安装git

复制sudo apt-get install git1.

配置git全局环境

复制git config --global user.name "yikoulinux"

git config --global user.email "7335817@qq.com"1.2.

修改commit默认打开的文本编辑工具

复制git config --global core.editor "vim"1.

开始克隆:

复制root@ubuntu:/home/peng/work# git clone https://gitee.com/yikoulinux/encryption.git

Cloning into encryption...

remote: Enumerating objects: 4, done.

remote: Counting objects: 100% (4/4), done.

remote: Compressing objects: 100% (4/4), done.

remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0

Unpacking objects: 100% (4/4), done.

Checking connectivity... done.1.2.3.4.5.6.7.8.

查看克隆下来的文件夹

复制root@ubuntu:/home/peng/work# ls

encryption

root@ubuntu:/home/peng/work# cd encryption/

root@ubuntu:/home/peng/work/encryption# ls

LICENSE1.2.3.4.5.

查看git log

复制root@ubuntu:/home/peng/work/encryption# git log

commit 5e0d6d12afb34a8082c6ef60f34f6e615c99746e

Author: 一口Linux <10221187+yikoulinux@user.noreply.gitee.com>

Date: Tue Dec 21 13:57:19 2021 +0000

Initial commit1.2.3.4.5.6.

拷贝代码到当前目录

复制root@ubuntu:/home/peng/work/encryption# ls

key.c key.h LICENSE main.c README.md1.2.

其中README.md是文档说明,采用Markdown格式编写。

添加源文件到本地仓库:

复制root@ubuntu:/home/peng/work/encryption# git add

*

root@ubuntu:/home/peng/work/encryption# git status

On branch master

Your branch is up-to-date with origin/master.

Changes to be committed:

(use "git reset HEAD ..." to unstage)

modified: LICENSE

new file: README.md

new file: key.c

new file: key.h

new file: main.c

Changes not staged for commit:

(use "git add ..." to update what will be committed)

(use "git checkout -- ..." to discard changes in working directory)

modified: .gitignore1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.

执行commit

复制root@ubuntu:/home/peng/work/encryption# git commit1.

添加commit 的 log信息【此时编辑工具是vim】

上传到服务器:

复制root@ubuntu:/home/peng/work/encryption# git push

warning: push.default is unset; its implicit value has changed in

Git 2.0 from matching to simple. To squelch this message

and maintain the traditional behavior, use:

git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

git config --global push.default simple

When push.default is set to matching, git will push local branches

to the remote branches that already exist with the same name.

Since Git 2.0, Git defaults to the more conservative simple

behavior, which only pushes the current branch to the corresponding

remote branch that git pull uses to update the current branch.

See git help config and search for push.default for further information.

(the simple mode was introduced in Git 1.7.11. Use the similar mode

current instead of simple if you sometimes use older versions of Git)

Username for https://gitee.com: yikoulinux

Password for https://yikoulinux@gitee.com:

Counting objects: 6, done.

Compressing objects: 100% (6/6), done.

Writing objects: 100% (6/6), 2.28 KiB | 0 bytes/s, done.

Total 6 (delta 0), reused 0 (delta 0)

remote: Powered by GITEE.COM [GNK-6.2]

To https://gitee.com/yikoulinux/encryption.git

5e0d6d1..484d5d4 master -> master1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.

其中会要求输入用户名(开头设置的名字yikoulinux)密码,密码输入时不会回显。

最终在gitee上显示结果:

这样我们就成功的将本地代码上传到服务器了。

6. 常用git命令

复制git clone 项目地址 拉项目

git pull 拉代码

git push 提交到仓库

git init 指令初始化一个git仓库

git add .添加文件

git commit -m "注释"提交至仓库。

git remote add origin https://git.oschina.net/你的用户名/项目名.

git,git push origin master即可完成推送

git checkout master 切换到master分支1.2.3.4.5.6.7.8.9.

7. 如果不想每次都输入用户名密码可以

(1)生成ssh密钥

复制ssh-keygen -C 7335817@qq.com -t rsa1.

会在用户目录~/.ssh/下建立相应的密钥文件。如果是管理员创建在目录/root/.ssh/下。b2b供应网

(2)上传公钥

使用命令cd ~/.ssh进入~/.ssh文件夹,输入

复制cat id_rsa.pub1.

打开id_rsa.pub文件,复制其中所有内容。接着访问git网页,点击SSH公钥,标题栏可以随意输入,公钥栏把刚才复制的内容粘贴进去。

此外,一口君还创建了一个基于Linux的聊天室的开源项目, 基功能包括登录、注册、公聊、私聊、数据库、数据加密等功能。其他功能后续会陆续完善。

https://gitee.com/yikoulinux/chat.git

本文转载自微信公众号「一口Linux」,可以通过以下二维码关注。转载本文请联系一口Linux公众号。

很赞哦!(69)