简体   繁体   English

如何使用 git bash 将分支更改为提交(master > main)?

[英]How do I change the branch to commit (master > main) using git bash?

I'll summarize what happened to my computer.我会总结一下我的电脑发生了什么。

What I wanted to do我想做的事

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

What happened发生了什么

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检查了它 - 除了它说“我的分支”我已经删除了图像

What I want to do now我现在想做什么

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 run git 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 to origin 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.

相关问题 如何在一个git commit中将master分支的更改合并到我的side project分支中? - How do I merge a master branch's changes into my side project branch in one git commit? Git:从master更新分支后,如何提交(?)更新文件? - Git: How do I commit(?) an updated file after updating my branch from master? 如何将 git 中的当前分支从 master 更改为 main - How to change current branch in git from master to main 如何在不更改主分支的情况下更改本地 git 存储库的功能分支? - How do I change a feature branch of a local git repo without changing the master branch? 我怎么能 git cherry-pick 从分支 A 到分支 B 但我在分支主机中的提交? - how can I git cherry-pick a commit from branch A to branch B but I am in branch master? 使用 git,如何将主(上游)分支合并到主题分支中,但看到差异,就好像我将主题分支合并到主分支中一样? - Using git, how do I merge the main (upstream) branch into a topic branch but see the differences as if I merged the topic branch into the main branch? 如何将 git 项目从使用 master 作为默认分支迁移到 main? - How to migrate a git project from using master as the default branch to main? 我如何使用git使旧的提交成为当前的主提交? - How do I make an old commit the current master commit with git? 如何使用git bash在主存储库中创建分支? - How to create branch in master repository using git bash? 如何将本地 Git 分支推送到远程的 master 分支? - How do I push a local Git branch to master branch in the remote?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM