Git 推送到私有仓库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18842120/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git pushing to a private repo
提问by irm
I have been working on my local on a web app and I was ask to push it to an empty(only read me file on it) private repo created just for this project. I'm new to git
and I'm having trouble doing so.
我一直在我的本地网络应用程序上工作,我被要求将它推送到一个专门为此项目创建的空的(只读取我的文件)私有存储库。我是新手git
,我在这样做时遇到了麻烦。
Can someone tell me what am I doing wrong?
有人能告诉我我做错了什么吗?
I first navigate to the main folder of the app in my local using command line and initialize git. After, I try cloning the remote repo with:
我首先使用命令行导航到本地应用程序的主文件夹并初始化 git。之后,我尝试使用以下命令克隆远程仓库:
git clone git://github.com/somename/Web-App.git
but I get the error:
但我收到错误:
Cloning into 'Web-App'... fatal: remote error: Repository not found.
克隆到“Web-App”...致命:远程错误:未找到存储库。
I know the repo is there.. Do I actually need to clone or pull from that remote first or is there a way to just push to that repo.
我知道 repo 在那里..我真的需要先从那个远程克隆或拉取,还是有办法只推送到那个 repo。
Again, all I'm trying to do is to get the files that I have in my local pushed to a specific repo that I was given access to.
同样,我想要做的就是将我在本地拥有的文件推送到我有权访问的特定存储库。
I will really appreciate any help.
我真的很感激任何帮助。
回答by palerdot
Let us say 'yourWebApp' is the folder you have your local web app. Change it to the directory
假设“yourWebApp”是您拥有本地 Web 应用程序的文件夹。将其更改为目录
cd 'yourWebApp'
Init git in the folder
在文件夹中初始化 git
git init
Now add your github url as a remote
现在将您的 github url 添加为远程
git remote add origin git://github.com/somename/Web-App.git
Here originis the short name for your url
这里的origin是你的 url 的简称
Now pull the read me file from the github repo
现在从 github repo 中提取 read me 文件
git pull origin master
Now push your web app to the github repository
现在将您的 Web 应用程序推送到 github 存储库
git push origin master
Here it is assumed that you are in your master, the default branch
这里假设您在master,默认分支
Here pulling your readme files is necessary to merge the readme file with your local work. If your github repository is empty, you can skip the pull and directly push to your github repository.
此处需要拉取自述文件以将自述文件与本地工作合并。如果你的github仓库是空的,可以跳过pull直接push到你的github仓库。
On the other hand, if you want to use clone, there is no need to init as clone automatically sets up git in the directory. clonealso sets your remote git url. In that case, your workflow should be
另一方面,如果您想使用clone,则无需初始化,因为clone 会自动在目录中设置git。clone还设置您的远程 git url。在这种情况下,您的工作流程应该是
clone -> push
回答by Ken Shirriff
To push to a private repository, you probably want to fork it, push your changes to your copy (which will stay private), and then create a pull request. When I tried to push directly to a private repository, I got the puzzling "remote: Repository not found. fatal" message, even though I could pull just fine.
要推送到私有存储库,您可能希望对其进行分叉,将更改推送到您的副本(将保持私有),然后创建拉取请求。当我尝试直接推送到私有存储库时,我收到了令人费解的“远程:未找到存储库。致命”消息,尽管我可以正常拉取。
回答by user3887498
I was facing the same problem. I was able to solve this by removing old credentials from windows.
我面临同样的问题。我能够通过从 Windows 中删除旧凭据来解决这个问题。
- Open Control Panel from the Start menu
- Go to User Accounts -> Credential Manager -> Manage Windows Credentials
- Delete any credentials related to Git or GitHub
- 从开始菜单打开控制面板
- 转到用户帐户 -> 凭据管理器 -> 管理 Windows 凭据
- 删除与 Git 或 GitHub 相关的任何凭据
Once I did this, it started working again.
一旦我这样做了,它又开始工作了。
回答by WyssMan
git clone is a little bit overkill for this purpose.
git clone 为此目的有点矫枉过正。
The mechanism that git provides to deal with other servers is fittingly called remote. This is typically automatically set up when you clone, explaining why that was your instinct.
git 提供的用于处理其他服务器的机制被恰当地称为远程。这通常在您克隆时自动设置,解释为什么这是您的本能。
Documentation can be found here:
文档可以在这里找到:
http://git-scm.com/book/en/Git-Basics-Working-with-Remotes
http://git-scm.com/book/en/Git-Basics-Working-with-Remotes
Some summary commands:
一些总结命令:
git remote add [remote-name] [branch-name]
git fetch [remote-name]
git push [remote-name] [branch-name]
In addition, you might consider setting up tracking branches, which will eliminate the need to qualify the remote name each time you type a command. Documentation for that use case is here.
此外,您可能会考虑设置跟踪分支,这将消除每次键入命令时限定远程名称的需要。该用例的文档在这里。
http://git-scm.com/book/en/Git-Branching-Remote-Branches
http://git-scm.com/book/en/Git-Branching-Remote-Branches
Usually, if you clone a repository, git executes
git checkout -b master [remotename]/master
通常,如果您克隆存储库,则 git 会执行
git checkout -b master [remotename]/master
Your tracking branch doesn't have to be master though.
不过,您的跟踪分支不必是主分支。
Hope this helps.
希望这可以帮助。