如何使用 Git 对远程存储库进行初始推送?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2337281/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 07:56:16  来源:igfitidea点击:

How do I do an initial push to a remote repository with Git?

gitversion-control

提问by Donald Hughes

I've read through countless tutorials and I keep coming up short. Here's what I've got:

我已经阅读了无数的教程,但我一直在总结。这是我所拥有的:

-- I'm running RubyMine on my Windows desktop
-- I've installed Git on my WebFaction hosting account per their instructions
-- Git appears to be working fine on both machines

-- 我在 Windows 桌面上运行 RubyMine
-- 我已经按照他们的说明在我的 WebFaction 托管帐户上安装了 Git
-- Git 似乎在两台机器上都运行良好

Here's what I'm doing:
1. On server:
         a. mkdir project
         b. git init
         c. git add .
         d. git commit <--- "nothing to commit"
2. On client:
         a. Create new project in RubyMine.
         b. "git init" in top directory of project
         c. "Push changes" to server <---- "failed to push some refs to...".

下面是我在做什么:
1.在服务器:
         一。mkdir项目
         b. git 初始化
         C. git 添加。
         d. git的承诺“---“没有承诺”
2.在客户端:
         一。在 RubyMine 中创建新项目。
         湾 项目
         c的顶级目录中的“git init” 。“推送更改”到服务器<----“无法将某些引用推送到...”。

What steps am I missing?

我缺少哪些步骤?

回答by Josh Lindsey

On server:

在服务器上:

mkdir my_project.git
cd my_project.git
git --bare init

On client:

在客户端:

mkdir my_project
cd my_project
touch .gitignore
git init
git add .
git commit -m "Initial commit"
git remote add origin [email protected]:/path/to/my_project.git
git push origin master

Note that when you add the origin, there are several formats and schemas you could use. I recommend you see what your hosting service provides.

请注意,当您添加源时,您可以使用多种格式和模式。我建议您查看您的托管服务提供的内容。

回答by Michael

You can try this:

你可以试试这个:

on Server:

在服务器上:

adding new group to /etc/grouplike (example)

添加新组以/etc/group喜欢(示例)

mygroup:1001:michael,nir

create new git repository:

创建新的 git 存储库:

mkdir /srv/git
cd /srv/git
mkdir project_dir
cd project_dir
git --bare init (initial git repository )
chgrp -R mygroup objects/ refs/ (change owner of directory )
chmod -R g+w objects/ refs/ (give permission write)

on Client:

在客户端:

mkdir my_project
cd my_project
touch .gitignore
git init
git add .
git commit -m "Initial commit"
git remote add origin [email protected]:/path/to/my_project.git
git push origin master

(Thanks Josh Lindsey for client side)

(感谢 Josh Lindsey 的客户端)

after Client, do on Server this commands:

在客户端之后,在服务器上执行以下命令:

cd /srv/git/project_dir
chmod -R g+w objects/ refs/

If got this error after git pull:

如果在 git pull 后出现此错误:

There is no tracking information for the current branch. Please specify which branch you want to merge with. See git-pull(1) for details

git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:

git branch --set-upstream new origin/<branch>

try:

尝试:

git push -u origin master

It will help.

我会帮你的。

回答by Benjamin Wohlwend

You have to add at least one fileto the repository before committing, e.g. .gitignore.

在提交之前,您必须至少向存储库添加一个文件,例如.gitignore.

回答by Maria

If your project doesn't have an upstream branch, that is if this is the very first time the remote repository is going to know about the branch created in your local repository the following command should work.

如果您的项目没有上游分支,也就是说,如果这是远程存储库第一次知道在本地存储库中创建的分支,则以下命令应该可以工作。

git push --set-upstream origin <branch-name>

回答by JWo

@Josh Lindsey already answered perfectly fine. But I want to add some information since I often use ssh.

@Josh Lindsey 已经回答得很好。但我想补充一些信息,因为我经常使用 ssh。

Therefore just change:

因此只需更改:

git remote add origin [email protected]:/path/to/my_project.git

to:

到:

git remote add origin ssh://[email protected]/path/to/my_project

Note that the colon between domain and path isn't there anymore.

请注意,域和路径之间的冒号不再存在。

回答by Dave Bacher

You need to set up the remote repository on your client:

您需要在客户端上设置远程存储库:

git remote add origin ssh://myserver.com/path/to/project