我有一个本地Git存储库。我想让它在远程的、启用ssh的服务器上可用。我怎么做呢?
当前回答
我有一个覆盆子,我可以通过ssh通过公钥访问(没有提示密码)。
在覆盆子上,我做到了
mkdir -p /home/pi/my/repo
cd /home/pi/my/repo
git init --bare
在我的笔记本电脑上,我做到了
git clone ssh://pi@raspberry/home/pi/my/repo
cd myrepo
touch README.md
git add README.md
git commit -m "First commit"
git push
就是这样
其他回答
我认为你在远程端创建一个裸库,git init——bare,添加远程端作为本地存储库的推/拉跟踪器(git remote add origin URL),然后在本地输入git push origin master。现在任何其他存储库都可以从远程存储库中提取。
在当前代码文件夹中。
git remote add origin http://yourdomain-of-git.com/project.git
git push --set-upstream origin master
然后通过
git remote --v
通常你只需要使用init命令就可以建立一个git repo
git init
在您的情况下,已经有一个回购的远程可用。根据您如何访问远程repo (url内的用户名或处理验证的ssh密钥),只使用clone命令:
git clone git@[my.url.com]:[git-repo-name].git
还有其他方法可以克隆回购。如果您在计算机上设置了ssh密钥,在提取存储库时进行验证,则可以使用这种方法调用它。如果您希望在其中包含密码和用户名以登录到远程存储库,则该url还有其他组合。
我有一个覆盆子,我可以通过ssh通过公钥访问(没有提示密码)。
在覆盆子上,我做到了
mkdir -p /home/pi/my/repo
cd /home/pi/my/repo
git init --bare
在我的笔记本电脑上,我做到了
git clone ssh://pi@raspberry/home/pi/my/repo
cd myrepo
touch README.md
git add README.md
git commit -m "First commit"
git push
就是这样
远程存储库通常是一个裸存储库——Git存储库 没有工作目录。因为存储库仅用于 对于协作点,没有理由检查快照 在磁盘上;它只是Git数据。用最简单的话来说,就是赤裸 Repository是项目的.git目录的内容 什么都没有。
你可以用下面的代码创建一个git仓库:
$ git clone --bare /path/to/project project.git
有一个远程git存储库的选项是使用SSH协议:
A common transport protocol for Git when self-hosting is over SSH. This is because SSH access to servers is already set up in most places — and if it isn’t, it’s easy to do. SSH is also an authenticated network protocol and, because it’s ubiquitous, it’s generally easy to set up and use. To clone a Git repository over SSH, you can specify an ssh:// URL like this: $ git clone ssh://[user@]server/project.git Or you can use the shorter scp-like syntax for the SSH protocol: $ git clone [user@]server:project.git In both cases above, if you don’t specify the optional username, Git assumes the user you’re currently logged in as. The Pros The pros of using SSH are many. First, SSH is relatively easy to set up — SSH daemons are commonplace, many network admins have experience with them, and many OS distributions are set up with them or have tools to manage them. Next, access over SSH is secure — all data transfer is encrypted and authenticated. Last, like the HTTPS, Git and Local protocols, SSH is efficient, making the data as compact as possible before transferring it. The Cons The negative aspect of SSH is that it doesn’t support anonymous access to your Git repository. If you’re using SSH, people must have SSH access to your machine, even in a read-only capacity, which doesn’t make SSH conducive to open source projects for which people might simply want to clone your repository to examine it. If you’re using it only within your corporate network, SSH may be the only protocol you need to deal with. If you want to allow anonymous read-only access to your projects and also want to use SSH, you’ll have to set up SSH for you to push over but something else for others to fetch from.
欲了解更多信息,请查看参考文献: 服务器上的Git -协议
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式
- git pull -rebase和git pull -ff-only之间的区别