[英]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
推送到远程master
: git 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.