链上哥 發表於 2022-1-10 18:55:00

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

<p>之前编写了几个适合新手的小项目,<br>
为方便大家学习和下载代码,<br>
决定把代码上传到gitee服务器。</p>
<p>不得不说,git是一个非常好用的代码版本管理工具,</p>
<p>本文手把手教大家如何将自己编写的代码上传到Gitee。</p>
<h2 id="1-注册账号">1. 注册账号</h2>
<p>打开网页</p>
<pre><code class="language-bash">https://gitee.com/
</code></pre>
<p><img src="https://img-blog.csdnimg.cn/da6fecf2df364fa4a5ff2e74aa081a6a.png?"><br>
点击注册,<br>
输入一个自己喜欢的域名,<code>yikoulinux</code><br>
输入手机号,验证即可<br>
<img src="https://img-blog.csdnimg.cn/1321f8b538464837a3a9a3a66242cf21.png?"></p>
<p>点击<code>注册并绑定</code> 即可。<br>
<img src="https://img-blog.csdnimg.cn/7bf6249ce3e9419aa4771b5fa454f337.png?"></p>
<h2 id="2绑定微信">2.绑定微信</h2>
<p>点击<code>头像-&gt;设置</code><br>
<img src="https://img-blog.csdnimg.cn/67e257f0a27342778f1539b1bab40d58.png?"><br>
<img src="https://img-blog.csdnimg.cn/0b3ab6a9e63d415594a0d127c87ba30b.png?">然后会弹出二维码,<br>
用自己的微信扫描二维码即可。</p>
<h2 id="2-绑定邮箱">2. 绑定邮箱</h2>
<p>后续版本管理操作需要绑定邮箱才能继续操作。</p>
<p>点击<code>头像-&gt;设置</code><br>
<img src="https://img-blog.csdnimg.cn/dc9d26f13d654485873c2164bb09ae30.png?"></p>
<p>点击 左边<code>邮箱管理</code>-&gt;<code>新增</code><br>
然后输入刚才设置的gitee登录密码<br>
<img src="https://img-blog.csdnimg.cn/eb4ab2fd515c4934be7ebbc30bccadcc.png?"></p>
<p>正确会进入下面页面, 输入自己的邮箱(一口君用的QQ邮箱)<br>
<img src="https://img-blog.csdnimg.cn/ab0011626c8f4bd5ad14eae637a8eab9.png?"></p>
<p>点击<code>确定</code><br>
<img src="https://img-blog.csdnimg.cn/89f9b9e15fe24de2aa49b2af1feb6298.png?"></p>
<p>然后登录自己邮箱,点击对应的链接即可。<br>
<img src="https://img-blog.csdnimg.cn/188ef9d134ad483a8a31886a5f431b77.png?"></p>
<h2 id="3-新建仓库">3. 新建仓库</h2>
<p>点击头像左侧的<code>+</code>-&gt;<code>新建仓库</code><br>
<img src="https://img-blog.csdnimg.cn/35bbab21b306468180cdff94e1c12bb7.png?"></p>
<p>输入名称以及开源许可证等。<br>
<img src="https://img-blog.csdnimg.cn/442bb738db364442a5bc31deeab8c26e.png?">点击<code>创建</code>即可。</p>
<h2 id="4-clone克隆仓库到本地">4. clone克隆仓库到本地</h2>
<p>复制仓库链接:</p>
<p><img src="https://img-blog.csdnimg.cn/f9207ba387474c94986ae6ee77a49002.png?"></p>
<p>进入ubuntu<br>
如果没有安装git,可以执行以下命令安装git</p>
<pre><code class="language-bash">sudo apt-get install git
</code></pre>
<p>配置git全局环境</p>
<pre><code class="language-bash">git config --global user.name "yikoulinux"
git config --global user.email "7335817@qq.com"
</code></pre>
<p>修改commit默认打开的文本编辑工具</p>
<pre><code class="language-bash">git config --global core.editor "vim"
</code></pre>
<p>开始克隆:</p>
<pre><code class="language-bash">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.
</code></pre>
<p>查看克隆下来的文件夹</p>
<pre><code class="language-bash">root@ubuntu:/home/peng/work# ls
encryption
root@ubuntu:/home/peng/work# cd encryption/
root@ubuntu:/home/peng/work/encryption# ls
LICENSE
</code></pre>
<p>查看git log</p>
<pre><code class="language-bash">root@ubuntu:/home/peng/work/encryption# git log
commit 5e0d6d12afb34a8082c6ef60f34f6e615c99746e
Author: 一口Linux &lt;10221187+yikoulinux@user.noreply.gitee.com&gt;
Date:   Tue Dec 21 13:57:19 2021 +0000

    Initial commit
</code></pre>
<p>拷贝代码到当前目录</p>
<pre><code class="language-bash">root@ubuntu:/home/peng/work/encryption# ls
key.ckey.hLICENSEmain.cREADME.md   
</code></pre>
<p>其中README.md是文档说明,采用Markdown格式编写。</p>
<p>添加源文件到本地仓库:</p>
<pre><code class="language-bash">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 &lt;file&gt;..." 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 &lt;file&gt;..." to update what will be committed)
(use "git checkout -- &lt;file&gt;..." to discard changes in working directory)

        modified:   .gitignore
</code></pre>
<p>执行commit</p>
<pre><code class="language-bash">root@ubuntu:/home/peng/work/encryption# git commit
</code></pre>
<p>添加commit 的 log信息【此时编辑工具是vim】</p>
<p><img src="https://img-blog.csdnimg.cn/0151e39b780a4024930494bc3d831968.png?"></p>
<p>上传到服务器:</p>
<pre><code class="language-bash">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
To https://gitee.com/yikoulinux/encryption.git
   5e0d6d1..484d5d4master -&gt; master
</code></pre>
<p>其中会要求输入用户名(开头设置的名字yikoulinux)密码,密码输入时不会回显。</p>
<p>最终在gitee上显示结果:</p>
<p><img src="https://img-blog.csdnimg.cn/701cdc6287784871a3ea136cd6b3efa5.png?"><br>
这样我们就成功的将本地代码上传到服务器了。</p>
<h2 id="5-常用git命令">5. 常用git命令</h2>
<pre><code class="language-bash">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分支
</code></pre>
<h2 id="6-如果不想每次都输入用户名密码可以">6. 如果不想每次都输入用户名密码可以</h2>
<h3 id="1生成ssh密钥">(1)生成ssh密钥</h3>
<pre><code class="language-bash">ssh-keygen -C '7335817@qq.com' -t rsa
</code></pre>
<p>会在用户目录<code>~/.ssh/</code>下建立相应的密钥文件。<br>
如果是管理员创建在目录<code>/root/.ssh/</code>下。</p>
<h3 id="2上传公钥">(2)上传公钥</h3>
<p>使用命令<code>cd ~/.ssh进入~/.ssh</code>文件夹,输入</p>
<pre><code class="language-bash">cat id_rsa.pub
</code></pre>
<p>打开id_rsa.pub文件,复制其中所有内容。接着访问git网页,点击SSH公钥,标题栏可以随意输入,公钥栏把刚才复制的内容粘贴进去。</p>
<p><img src="https://img-blog.csdnimg.cn/3c1524e57fc24298a820d3398d5b81a9.png?"><br>
此外,一口君还创建了一个<strong>基于Linux的聊天室的开源项目</strong>,<br>
基功能包括登录、注册、公聊、私聊、数据库、数据加密等功能。<br>
其他功能后续会陆续完善。</p>
<pre><code class="language-bash">https://gitee.com/yikoulinux/chat.git
</code></pre>
<p>最后欢迎各位给我的开源项目点个星!</p>
<p>感谢了!</p>


</div>
<div id="MySignature" role="contentinfo">
    欢迎关注公众号:一口Linux<br><br>
来源:https://www.cnblogs.com/yikoulinux/p/15785598.html
頁: [1]
查看完整版本: 手把手教你如何上传代码到gitee服务器