简体   繁体   English

无法从本地存储库初始化远程 git 存储库

[英]Cannot initialize remote git repository from local repository

I'm trying to initialize a local project as a new repository on Github, and am running into a problem when running the git add.我正在尝试将本地项目初始化为 Github 上的新存储库,但在运行git add. command.命令。 My project has the following file structure (which I think is the source of the problem, but am not sure why):我的项目具有以下文件结构(我认为这是问题的根源,但不确定原因):

PROJECT_NAME (top level folder) PROJECT_NAME (顶级文件夹)

  • PROJECT_NAME_OLD (subfolder with project files inside) PROJECT_NAME_OLD (包含项目文件的子文件夹)
  • PROJECT_NAME_UPDATED (subfolder with other project files inside) PROJECT_NAME_UPDATED (包含其他项目文件的子文件夹)

Not sure what the exact file structure terminology is, but here is the process I have used so far to try and initialize the project with a remote repository:不确定确切的文件结构术语是什么,但这是我到目前为止用来尝试使用远程存储库初始化项目的过程:

  1. From terminal, change directory into PROJECT_NAME and run git init (successful)从终端,将目录更改为PROJECT_NAME并运行git init (成功)
  2. Run git add.运行git add. (failed with the following error: 'PROJECT_NAME/' does not have a commit checked out, fatal: adding files failed ) (失败并出现以下错误: 'PROJECT_NAME/' does not have a commit checked out, fatal: adding files failed

  3. Run git remote add origin git@github.com:unique_url (successful)运行git remote add origin git@github.com:unique_url (成功)

  4. Run git push -u origin master (failed with the following error: error: src refspec master does not match any )运行git push -u origin master (失败并出现以下错误: error: src refspec master does not match any

When trying to run the git commit -m"message" command, I received a message saying that the files for PROJECT_NAME_OLD/ and PROJECT_NAME_UPDATED/ were untracked as well as a new file .DS_STORE , but I'm not sure what this means or how to fix it?尝试运行git commit -m"message"命令时,我收到一条消息,指出PROJECT_NAME_OLD/PROJECT_NAME_UPDATED/的文件以及新文件.DS_STORE未被跟踪,但我不确定这意味着什么或如何实现要解决这个问题?

I am wondering what I'm doing wrong here, and if there is a way for me to undo any incorrect steps I've taken and initialize this repository with the file structure that I already have in place?我想知道我在这里做错了什么,是否有办法撤消我采取的任何不正确的步骤并使用我已经存在的文件结构初始化此存储库?

I think the problem is in the branch.我认为问题出在分支上。 Take the following steps:-采取以下步骤:-

  1. Check if there is the creation of.git file after doing git init .执行git init后检查是否创建了.git 文件。
  2. Check the branch using git branch and a look if you are at the master branch.使用git branch检查分支,看看你是否在主分支。
  3. Then check the status of the files using git status it will show if any file is changed.然后使用git status检查文件的状态,如果有任何文件被更改,它将显示。
  4. Then do git add individual file or git add.然后执行git add individual filegit add. as you wish.如你所愿。
  5. Then commit the changes.然后提交更改。
  6. And then push.然后推。

If git add.git add. fails there is a possibility that the next steps will also fail.And also check git remote -v if your origin branch is at the remote.失败,接下来的步骤也有可能失败。如果您的原始分支在远程,还要检查git remote -v

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM