简体   繁体   English

如何使本地更改显示在github存储库中?

[英]How do I make my local changes show up to github repository?

I made a private github repository in which i cloned a repository I needed to work on. 我创建了一个私人github存储库,在其中克隆了需要使用的存储库。 I have all their files locally and already finished coding but I am unable to reflect those changes onto my private github repository. 我在本地拥有所有文件,并且已经完成编码,但是我无法将这些更改反映到我的私有github存储库中。

so this is what i did after cloning the repository 所以这是我克隆存储库后所做的

git checkout -b private
git remote add private git@github.com:<github-username>/<repositoryname>.git
git push private -u master

however this would always fail when i tried again it worked but showed this 但是,当我再次尝试时,它总是会失败,但是显示了这一点

Enumerating objects: 42, done.
Counting objects: 100% (42/42), done.
Delta compression using up to 8 threads
Compressing objects: 100% (36/36), done.
Writing objects: 100% (42/42), 22.55 KiB | 7.51 MiB/s, done.
Total 42 (delta 15), reused 0 (delta 0)
remote: Resolving deltas: 100% (15/15), done.
remote: 
remote: Create a pull request for 'master' on GitHub by visiting:
remote:      https://github.com/<githubusername>/<repositoryname>/pull/new/master
remote: 
To https://github.com/<githubusername>/<repositoryname>
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'private'.

it was supposed to say private -> master so i know something is not right 应该说是私人的->主人,所以我知道有些不对劲

What i am trying to do is have a new branch track my changes and have a remote for my private repository so i can push my new branch to the master branch of my repository but i think it is trying to push to the other person's master. 我想做的是有一个新分支跟踪我的更改,并为我的私有存储库提供一个远程,以便我可以将新分支推送到存储库的master分支,但是我认为它正在尝试推送到其他人的master。

EDIT: when i want to push it tells me to use this first 编辑:当我想推动它告诉我首先使用它

git push --set-upstream origin private git push --set-upstream原始私有

but when i do that i get denied access by the repository i cloned, this is why i think it is trying to push to their master instead of mine even tho i used my username and repository when setting it up 但是当我这样做时,我克隆的存储库被拒绝访问,这就是为什么我认为它甚至试图在设置时使用我的用户名和存储库,而不是我的主存储库

You created a branch named private (by running git checkout -b private ), but then you've only pushed your master branch (by running git push private master ). 您创建了一个名为private的分支(通过运行git checkout -b private ),但是您仅推送了master分支(通过运行git push private master )。 Remember that the syntax of the push command is: 请记住, push命令的语法为:

git push <remote> <refspec>

That first parameter specifies the name of a remote, not the name of a branch. 第一个参数指定远程的名称,而不是分支的名称。

If you want to push your local branch private to your remote named private , you would write: 如果要将本地分支private推送到远程名为private ,则应编写:

git push -u private private

If you want to rename your local private branch to be master on the remote, you would write: 如果要将本地private分支重命名为远程master ,请编写:

git push -u private private:master

Everything I see in the question is Ok. 我在问题中看到的一切都很好。 There are no errors, local branch master has been successfully pushed to remote master . 没有错误,本地分支master已成功推送到远程master Your expectation to see private -> master is wrong: private is the name of the remote, git uses it to get its URL from config. 您期望看到private -> master是错误的: private是远程的名称, git使用它从配置中获取其URL。 But git pushes branches so it pushes master to master and you see master -> master . 但是git推送分支,因此它将master推送到master ,您会看到master -> master

If you have a branch named private you have to push it separately: git push private -u private . 如果您有一个名为private的分支,则必须单独推送它: git push private -u private If you want the branch private to be pushed to remote master : git push private -u private:master but I recommend to make local and remote branch names to have exactly the same names. 如果您希望将分支private推送到远程mastergit push private -u private:master但我建议使本地和远程分支名称具有完全相同的名称。

As for the error 至于错误

! [rejected] private -> private (fetch first)
error: failed to push some refs to 'github.com/vdorozco/roster'
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.

see Cannot push to GitHub - keeps saying need merge 看到无法推送到GitHub-一直在说需要合并

You need update your local repository with git pull [--rebase] private master . 您需要使用git pull [--rebase] private master更新本地存储库。

https://stackoverflow.com/search?q=%5Bgit%5D+update+were+rejected https://stackoverflow.com/search?q=%5Bgit%5D+update+被+拒绝

The given link you comment above doesn't work properly. 您上面评论的给定链接无法正常工作。 As you told If you mind to push you local changes to remote simply you can do it from master. 正如您所说,如果您打算将本地更改推送到远程,则只需从master即可完成。

git push origin master

Then if you get a rejected result and not allow to push your code first you have to pull the code from remote master. 然后,如果您得到拒绝的结果并且不允许先推送代码,则必须从远程主服务器中提取代码。 (This happen because your have remote changes so you have to get them and updated code first). (发生这种情况是因为您有远程更改,所以您必须先获取它们并更新代码)。 So u should pull the code from master. 因此,您应该从管理员那里获取代码。

git pull origin master

Then you will show some process window over there. 然后,您将在那显示一些过程窗口。 close it and push code again. 关闭它并再次推送代码。

Case2: If you are in a create a branch you can simply do it by: 情况2:如果您在创建分支中,则可以通过以下方式简单地做到这一点:

git checkout -b <branch name>

Then you working over this branch commit over this branch. 然后,您在该分支上工作,在该分支上提交。 Then jump to master again by 然后再跳到掌握

git checkout master

If there any commits you want pull from remote master get them by 如果有任何您要从远程主服务器获取的提交,请通过

git pull origin master

Then your local master branch ahead new branch you have already made. 然后,在您已经创建的新分支之前,先在本地主分支。 So jump to that branch by checkout (like above jumb to master) & rebase with master 因此,请通过结帐跳到该分支(如上述jumb到master)并重新设置master

git rebase master

Then jump to master and again rebase with branch by 然后跳到主节点,然后再次分支建立基础

git rebase <branch name>

Then you can simply push your code to remote master 然后,您可以简单地将代码推送到远程主机

-u is only required when you create a new branch. -u仅在创建新分支时才需要。 Otherwise, you should just do git push private master or as a shorthand git push . 否则,您应该只执行git push private master或作为简写git push

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在我的本地未暂存更改中从Github PR视图显示差异更改? - How Do I show diff changes from the Github PR view in my local unstaged changes? 如何让我的新eclipse分支显示为github存储库中的新项目? - How do I get my new eclipse branch to show up as a new project in my github repository? 我如何撤消本地代表中的所有更改,并使其在github中克隆上游 - how do I undo all changes in my local rep and make it clone of upstream in github 如何从GitHUB到本地计算机进行更改? - How do I get changes from GitHUB to my local machine? 如何推送我从 github 克隆的存储库并对我的 github 存储库进行更改? - How do I push the repository I cloned from github and made changes to it to my github repo? 从github提取新版本时,如何丢弃Git存储库中的本地更改? - How can I throw away local changes in my Git repository when pulling a new version from github? 我如何让我的本地git反映出Github中的主人? - How do I make my local git reflect master in Github? 如何将 GitHub 存储库制作成 exe? - How do I make a GitHub repository into an exe? 如何将子模块添加到我现有的存储库,在本地进行更改,并将所有更改推送到我的 github? - How do I add a submodule to my existing repo, make changes locally, and push all changes to my github? 如何使用Windows GUI将本地站点连接到空的GitHub存储库? - How do I connect my local site to an empty GitHub repository with the windows GUI?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM