MeltingDog
MeltingDog

Reputation: 15404

Git: how to push a branch from existing project to GitHub?

I am working on an existing project that has already been set up (by someone else).

I've created a new branch and done my work. Now I'd like to push my work to GitHub so I can create a new Pull Request.

I'm not sure how I can do this.

So far I've:

git add .
git commit -m "Message"

I get this part, no problem

However, everything I look up online says the next step is to do something like:

git push origin master

but I don't want to push it to Master - just to GitHub.

Would anyone know what I should do to just push it up to GitHub to create a pull request?

Upvotes: 0

Views: 128

Answers (1)

ajxs
ajxs

Reputation: 3618

To create a pull request you'll first need to create a branch of your own to push your changes to. You can do this with:

git checkout -b <your_new_branch_name>

By the sounds of things, you've already committed your code to the master branch, which is a minor issue. In future you'll need to have checked out the branch you want to work on before committing any changes, but for now if you checkout a new branch from your current branch using the command above, the new branch will be created with the changes you've committed to master.

Once you've done this, push your new branch up to the remote origin using:

git push -u origin <your_new_branch_name>

Then you should be able to create a pull request using the Github ui.

For a better explanation of these concepts have a read of this. This explains some of the basics of branching and merging using git.

Upvotes: 2

Related Questions