git推送项目到码云(gitee)
<p>git推送项目到码云(gitee)</p><h1 id="git推送项目到码云gitee">git推送项目到码云(gitee)</h1>
<h3 id="创建账号">创建账号</h3>
<p>创建一个Gitee账号,我使用的是Gitee因为国内速度快~</p>
<h3 id="本地安装git">本地安装Git</h3>
<p>前往 Git 根据操作系统下载Git到本地</p>
<h3 id="ssh密钥">ssh密钥</h3>
<p>本地生成秘钥,右击桌面打开你的 git bash 第一次使用Git时 需要先生成ssh</p>
<pre><code>ssh-keygen -t rsa -C "your_email"
</code></pre>
<p>生成的秘钥一般在你操作系统用户下的.ssh目录中</p>
<h3 id="告诉本地系统">告诉本地系统</h3>
<p>将密钥告诉本地系统</p>
<pre><code>ssh-add ~/.ssh/id_rsa
</code></pre>
<p>(此处如果出现Could not open a connection to your authentication agent. 则先执行 ssh-agent bash)</p>
<h3 id="查看生成的公钥">查看生成的公钥</h3>
<pre><code>cat ~/.ssh/id_rsa.pub
</code></pre>
<h3 id="上传公钥">上传公钥</h3>
<p>复制该公钥粘贴到你的Gitee的SSH公钥页面,使用SSH公钥可以让你在你的电脑和码云通讯的时候使用安全连接(Git的Remote要使用SSH地址)</p>
<h3 id="配置user">配置User</h3>
<p>打开 git bash 需要配置:</p>
<pre><code>git config --global user.name "your_Name"
git config --global user.email"your_email"
</code></pre>
<h3 id="初始化本地git仓库">初始化本地Git仓库</h3>
<pre><code>git init
</code></pre>
<p>这条命令执行完毕后会多出一个.git文件夹</p>
<h3 id="添加变更文件">添加变更文件</h3>
<pre><code>git add . // 表示添加全部变更文件
</code></pre>
<h3 id="提交文件">提交文件</h3>
<pre><code>git commmit -am "message" // 表示提交全部变更文件
</code></pre>
<h3 id="添加远程地址">添加远程地址</h3>
<pre><code>git remote add origin git@gitee.com:你的gitee用户名/仓库名.git
</code></pre>
<h3 id="ssh测试">ssh测试</h3>
<pre><code>ssh -T git@gitee.com
</code></pre>
<p>显示Welcome to Gitee.com,你的用户名!说明ssh正确。</p>
<h5 id="可能出现的错误">可能出现的错误</h5>
<p>如果出现 fatal: remote origin already exists. 则执行</p>
<pre><code>git remote rm origin
</code></pre>
<h3 id="首次提交">首次提交</h3>
<p>第一次提交可能会出现如下错误</p>
<pre><code>error: failed to push some refs to 'https://gitee.com/tomFat/interview.git'
</code></pre>
<p>所以需要在提交前执行</p>
<pre><code>git pull
</code></pre>
<h3 id="合并两个版本库">合并两个版本库</h3>
<pre><code>git pull origin master --allow-unrelated-histories
</code></pre>
<h3 id="向github或gitee推送">向Github或Gitee推送</h3>
<pre><code>git push -u origin master
</code></pre>
<p>或git push 你的gitee上的仓库名master #推送到指定的仓库的master分支</p>
<p>或git push -u origin master -f #强制推送</p><br><br>
来源:https://www.cnblogs.com/guoyinghome/p/11229750.html
頁:
[1]