如何将提交的更改上传到我的 GitHub 存储库?
我使用 clone
在 GitHub 上创建了我的存储库的本地副本。
我修改了一些文件。然后我做了: git commit -a
现在我想将提交的更改保存到 GitHub 存储库。
我怎样才能做到这一点?
I used clone
to create a local copy of my repository on GitHub.
I modified a few files. Then I did:git commit -a
And now I want to save my committed changes to the GitHub repository.
How can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您推送您的更改:
如果与 master 不同,请将
master
替换为您要推送的分支的名称。如果自上次更新后分支已更新,则更改可能会被拒绝。在这种情况下,您必须首先提取远程分支上的最新更改:
或者,您可以在远程主控之上重新调整您的更改(这将阻止合并提交),方法是:
You push your changes:
Replace
master
with the name of the branch you want to push, if different from master.In case the branch was updated since your last update, the changes may be rejected. In that case you have to pull the latest changes on the remote branch first:
Optionally, you can rebase your changes on top of the remote master (this will prevent a merge commit), by using:
请按照以下步骤操作:
Follow this steps:
您想使用 git push 将更改推送到中央存储库。它可能会提示您输入 github 密码。
You want to push your changes to the central repo with
git push
. It might prompt you for your github password.要发布本地更改,请按照以下 3 个简单步骤操作:
git add
或git add *
添加所有内容git commit -m "Enter e message这里”
git Push
To publish your local changes follow the 3 simple steps below:
git add <filename>
orgit add *
to add everythinggit commit -m "Enter e message here"
git push
如果您想将代码/项目的更改提交到 github,请在终端中使用以下代码。
If you want to commit your changes of the code/ project into github use the below codes in your terminal.
问题中未涵盖的场景是分支保护应用于原始存储库。然后,当您尝试推送时,对
main
或master
的更改可能会被拒绝。最初的问题说“克隆我的存储库”,但您更有可能克隆您不是原始所有者的存储库。如果您更新了像
main
这样的受保护分支,并且随后的推送尝试被拒绝,则需要重命名您的分支。您可以选择尚未使用的分支名称并描述您所做的更改。可以使用 gitbranch -m < 重命名分支;分支名称>。
然后,您应该能够使用 git push 成功推送。
A scenario that's not covered in the question is when branch-protection applies to the original repository. Then, a change to
main
ormaster
is likely to be rejected when you attempt to push. The original question said "clone of my repository" but you're more likely to clone a repository of which you are not the original owner.If you have updated a protected branch like
main
and the subsequent push attempt has been rejected, you need to rename your branch. You can choose a branch name that isn't already used and describes the changes that you made.Branches can be renamed using git branch -m <branch name>.
Then, you should be able to push successfully using
git push
.