【发布时间】:2021-03-09 06:01:48
【问题描述】:
出于可访问性原因,我试图将一些本地未版本控制的代码推送到存储库中并将其上传到 GitHub。
我听从了here的建议
cd <local_dir>
git init
git add .
git commit -m "initial commit"
然后我在 github 上创建了一个新的 repo 并做了
git remote add origin https://github.com/...
git pull origin master --allow-unrelated-histories
git push --force-with-lease
但我现在在 github 上看到我有 2 个分支 'main' 和 'master' 我猜 github 在创建 repo 时创建了“main”,当我从本地 repo 同步时我创建了“master”
两个都需要吗?
我可以将master合并到main然后删除master吗?
目前这只是让我感到困惑
注意:我现在已经尝试(本地)
git branch -m master main
git push origin HEAD
但我遇到了一个错误
To https://github.com/<the-repo>
! [rejected] HEAD -> main (non-fast-forward)
error: failed to push some refs to 'https://github.com/<the-repo>'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
我错过了什么?
【问题讨论】:
-
是的,你可以。 Git 使用
master作为默认分支的名称。 Github 最近决定改一下main。您可以选择其中一个。
标签: git github version-control