I've cloned a private repo in github to my local machine. After I'm done making some changes, I want to push the branch back to github to propose a merge (or pull request, as github calls it).
How do I do that?
I'm absolutely new to github (I normally use bzr/launchpad, and the command was bzr push lp:~<username>/<master-branch>/<name of the new child branch>
. What is the equivalence of this in git
?).
[Edit: I found that my wording was confusing due to my little understanding of git's terminologies, I am going to re-describe what I did]
(bar
is the private repo)
$git clone [email protected]:foo/bar.git
$cd bar
$touch <some file> # ie., make some changes
$git commit ...
$ <<<<< NOW I need to push this back to github here.
From your comments above and your original question, you want to do a pull request on github but you've modified master
locally ... that's a problem. What you wanted to do is branch first, make the changes, commit locally, and push the branch. Then you could create a pull request on github from that branch.
First what you need to do to fix that is:
git branch mytopicbranch
git reset --hard origin/master
You now have a branch and have reset master
locally to what it is in the remote repo. You can now push your branch with:
git push origin mytopicbranch
Then on github you'll be able to create a pull request for that branch.
The normal flow would be to do the following:
git clone <remote repo>
<cd to directory>
git checkout -b mybranch
<make changes>
<commit changes>
git push origin mybranch
<create pull request on github>
Edit to add: This is for the reason you asked; wanting to do a "pull request". If you just want to push master
you'd simply do:
git push origin master
And your changes will be committed to master remotely.
The private master repo is NOT owned by me (ie., I don't have the permission to push my repo back to the master repo). I think I can only push my local repo back, and request the owner to merge it to the master
You seem to be confusing a lot things here. First of all, a repository is a single unit. When you clone a repository, you get a complete local copy of it.
If you cloned a repository, that is not owned by yourself and to which you have no write-rights, then you will not be able to push any changes to that repository. If that is the case, you will need to fork it first to your own GitHub account. To do that, click the fork button in the repository view. This will create a copy of the repository in your own account, which you will have push rights for.
So, if you have a local clone of the repository, you can do whatever you want. Nothing affects the remote repository, neither the original one, nor your GitHub fork. You can create as many branches as you want and commit whereever you want. Note here that branches are not some construct in Git. Branches are simple pointers to commits, so creating a branch is not doing much, and will have no impact on your structure unless you actually start committing.
If you have commits you want to push to a remote repository, you can do that by using git push
:
git push <remote> <local-branch>:<remote-branch>
So if you want to push your local master
branch into a branch test
on the remote named origin
, you can do git push origin master:test
. As you pushed explicitely to the remote branch test
(which does not need to exist previously), you will not touch the remote’s master
branch. The other variations of git push
are just abbreviations of the above command. For example git push <remote> <branch>
which is probably the the second to most common way to push things will push your local branch <branch>
to the tracking remote branch (usually the othe with the same name). So it’s more or less equivalent to <branch>:<branch>
. The most common way would be just git push
which will figure out the remote and branch on its own based on your configuration, but to be safe, you can just specify it explicitely.
So, coming back to your use case, I assume that you want to fork someone else’s repository to make a change to it and propose that change to the original author as a pull request. To do that, you should follow these steps:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With