[英]How do I change the branch to commit (master > main) using git bash?
I'll summarize what happened to my computer.我会总结一下我的电脑发生了什么。
To upload my local folder "freshman" to github repository named "Hanyang", I typed the commands below;要将我的本地文件夹“freshman”上传到名为“Hanyang”的 github 存储库,我输入了以下命令;
git init
git add freshman
git commit -m "blahblah"
git remote add origin https://github.com/myUsername/Hanyang.git
git push -u origin master
git push origin master
But I realized that the folder is well uploaded but inadvertently at the ' master ' branch, while the default branch was ' main '.但我意识到该文件夹已很好地上传,但无意中位于“ master ”分支,而默认分支是“ main ”。
So I manually deleted ' master ' branch in github, got back to git bash then tried git add freshman
again.所以我手动删除了 github 中的 ' master ' 分支,回到 git bash 然后再次尝试
git add freshman
。
Did I have to do something to change the target branch ( master > main ) before merely trying
git add freshman
again?在尝试
git add freshman
之前,我是否必须做一些事情来更改目标分支( master > main )?
Anyway unlike the first typing of the command, however, git bash says "nothing is added" even I checked it via git status
- besides it says "my branch is up to date with 'origin/master' " which I already deleted as the image .无论如何,与命令的第一次键入不同,git bash 说“没有添加任何内容”,即使我通过
git status
检查了它 - 除了它说“我的分支”我已经删除了图像。
In this situation, what should I do to upload my ''freshman'' folder to the main branch of the repository in github such that I can upload other folders (sophomore, etc.) after this?在这种情况下,我应该怎么做才能将我的 ''freshman'' 文件夹上传到 github 的存储库的主分支,这样我就可以在此之后上传其他文件夹(大二等)?
run
git branch
to see what branch you are on运行
git branch
看看你在哪个分支to switch to main if not on main run
git checkout main
如果不在主运行
git checkout main
if branch
main
doesn't exist locally you will need to rungit branch main
before checking it out如果分支
main
在本地不存在,则需要在检查之前运行git branch main
Then you can add your file, set the remote for the
main
branch, and push toorigin main
然后你可以添加你的文件,设置
main
分支的远程,并推送到origin main
git branch -M main git分支-M主
for more information, look under Branching & Merging有关更多信息,请查看分支和合并
https://github.com/joshnh/Git-Commands https://github.com/joshnh/Git-Commands
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.