远程仓库推送

作者: 郑馋师 | 来源:发表于2019-08-20 12:01 被阅读18次

前面笔者介绍了自己通过饥人谷网课学习到了本地仓库建立以及相关的知识。今天就来分享自己如何实现远程仓库的推送。
ps:笔者强烈建议使用sshkey进行配置而非https,因为ssh不需要每次都输入密码,比较方便。

远程仓库

其实也就是在网上建立一个属于你自己的仓库,以防止你的代码丢失或者方便你同时在家里和公司进行工作。git官网上是如此分析他的好处与坏处的。

The Pros

The pros of file-based repositories are that they’re simple and they use existing file permissions and network access. If you already have a shared filesystem to which your whole team has access, setting up a repository is very easy. You stick the bare repository copy somewhere everyone has shared access to and set the read/write permissions as you would for any other shared directory. We’ll discuss how to export a bare repository copy for this purpose in Getting Git on a Server.
This is also a nice option for quickly grabbing work from someone else’s working repository. If you and a co-worker are working on the same project and they want you to check something out, running a command like git pull /home/john/project is often easier than them pushing to a remote server and you subsequently fetching from it.

The Cons

The cons of this method are that shared access is generally more difficult to set up and reach from multiple locations than basic network access. If you want to push from your laptop when you’re at home, you have to mount the remote disk, which can be difficult and slow compared to network-based access.
It’s important to mention that this isn’t necessarily the fastest option if you’re using a shared mount of some kind. A local repository is fast only if you have fast access to the data. A repository on NFS is often slower than the repository over SSH on the same server, allowing Git to run off local disks on each system.
Finally, this protocol does not protect the repository against accidental damage. Every user has full shell access to the “remote” directory, and there is nothing preventing them from changing or removing internal Git files and corrupting the repository.

可以看出,虽然他的确上传的时候比较慢一些,以及如果网站遭到攻击可能会导致代码流失,但是只要你同时本地和远程仓库都保存你的代码,以及选择一个比较好的远程仓库,总体而言还是利大于弊,可以节省很多时间。

推到哪里

这个仓库是github,相信无论菜鸟或者老手都肯定非常清楚这个网站了,因为他和我们工作一点一滴息息相关。

GitHub is an American company that provides hosting for software development version control using Git. It is a subsidiary of Microsoft, which acquired the company in 2018 for $7.5 billion.[4] It offers all of the distributed version control and source code management (SCM) functionality of Git as well as adding its own features. It provides access control and several collaboration features such as bug tracking, feature requests, task management, and wikis for every project.[5]
GitHub offers plans for free, professional, and enterprise accounts.[6] Free GitHub accounts are commonly used to host open source projects.[7] As of January 2019, GitHub offers unlimited private repositories to all plans, including free accounts.[8] As of May 2019, GitHub reports having over 37 million users[9] and more than 100 million repositories[10] (including at least 28 million public repositories),[11] making it the largest host of source code in the world.[12]
—————————— wikipedia

以上是来自维基百科的解释,简而言之是一个用户多,内容多,覆盖地区多的it网站,这次的推送也是需要推到这个网站上面,所以需要先行注册一个账号。这个不在这里赘述。

如何操作

言归正传,笔者选用的是ssh key的方式上传代码,首先打开github创建一个仓库。


创建自己的仓库

创建好后,会看见这样一个界面,然后将笔者画红色框框的代码复制粘贴即可。


注意是SSH!!

注意这里最好是通过ssh key进行上传,因为这样不用每次输密码比较方便。


上传成功
注意!!!
这里是要先建立自己的本地仓库才可以上传,如果后面有什么更改的地方直接在commit之后
git push

即可,非常方便快捷。

相关文章

  • 基础git

    创建本地仓库 创建远程仓库 将本地仓库代码推送到远程,默认只创建了master分支 本地有变化推送到远程 远程有变...

  • push

    基础 将本地仓库中的数据推送到远程仓库中。 推送数据之前,应该先更新远程库中的数据。 git push <远程主机...

  • 踩坑日常

    基本推送流程 克隆远程仓库到本地仓库:git clone 仓库地址(ssh/http)本地仓库连接远程仓库:git...

  • 远程仓库推送

    前面笔者介绍了自己通过饥人谷网课学习到了本地仓库建立以及相关的知识。今天就来分享自己如何实现远程仓库的推送。ps:...

  • 课程笔记-远程库及分支

    推送到远程空仓库 分支操作

  • git初识(常用git命令集合)

    一、本地创建git项目推送到远程仓库 1.查看本地库的远程仓库地址 git remote -v 2. 远程仓库地...

  • git初识(常用git命令汇总)

    一、本地创建git项目推送到远程仓库 1.查看本地库的远程仓库地址 git remote -v 2. 远程仓库地...

  • 基本用法

    本地与远程:push 命令会把本地仓库推送到远程仓库(比如gitbub,码云)在push之前要与某个远程仓库建立连...

  • GitHub简单使用

    GITHUB使用 1. 添加远程仓库 2. 推送项目到远程仓库 3. 下载代码

  • 个人使用Git-----本地仓库到远程仓库

    先创建本地仓库----》本地代码维护---》 创建远程仓库----》关联----> 推送到远程! 区别: 本地和远...

网友评论

    本文标题:远程仓库推送

    本文链接:https://www.haomeiwen.com/subject/ipiusctx.html