用(当前)非git文件夹替换分支中的所有文件和文件夹

Replace all files and folders in branch with (currently) non-git folder

请记住,我是 Git 的新手,对术语了解不多

我在 GitHub 存储库上有一个分支 reference-redo 和一个不同的(非 git)文件夹,我想替换 [=13] 的内容=]分支.

正在打开 Git 中的文件夹 bash:

git init:添加一个 .git 文件夹(说它初始化了一个空的 Git 存储库)

git add .: 添加所有文件和文件夹(有关于 LF 被 CR LF 替换的警告但没有错误)

git commit -m 'Fixed usage of references for ObjectPointer type': 'create mode ...' 14 个文件

git remote add origin https://github.com/me/repo-name.git: 没有输出但也没有错误

git checkout -b reference-redo: 切换到新分支 'reference-redo'

git remote -v

git push origin reference-redo

 ! [rejected]        reference-redo -> reference-redo (fetch first)
error: failed to push some refs to 'https://github.com/me/repo-name.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

这似乎是因为我正在替换 分支的文件,而不是更新。我必须推送到新分支还是可以推送当前目录?

运行 git remote show origin 说明分支确实存在:

  Remote branches:
    functions      new (next fetch will store in remotes/origin)
    master         new (next fetch will store in remotes/origin)
    reference-redo new (next fetch will store in remotes/origin)
  Local refs configured for 'git push':
    master         pushes to master         (local out of date)
    reference-redo pushes to reference-redo (local out of date)

git-push

如果您想覆盖该分支中的全部历史记录,您可以git push --force

否则,通过删除和复制本地文件管理器中的文件进行定期更新,并像其他任何时候一样提交。