1

Situation: open-source project with multiple branches, and my fork of it for contributions. I want to create a new branch for pull requests on github. I want to base this branch on one of the existing branches on the open-source project, BUT I do NOT want my commits to go into that original branch.

As per my experience, if I clone my fork, execute git checkout -b my-branch origin/some-branch and then commit+push to my-branch, in Github the commits will go to some-branch and not my-branch. Obviously, this is problematic if I want to make multiple branches for multiple pull requests on the same branch.

The workaround that I've found for this is the following:

git checkout -b some-branch origin/some-branch

git checkout -b my-branch (new branch based on some-branch, but not tracking it)

after that - commit+push, first push will create my-branch on Github.

However, this leaves me with an extra local copy of some-branch. I can delete it later, obviously, but is there a way to avoid creating it at all? Is there a way to create my-branch, based on origin/some-branch, but not tracking it, in one command, without the extra branch in the middle?

1
  • You may want to post what your push.default is set to as well as your Git version. Both of these can influence the behavior you are seeing when you push. Commented Dec 29, 2014 at 0:59

1 Answer 1

2

Use the SHA1 hash of the same commit instead of origin/some-branch. Example:

git checkout -b my-branch 92fc7a2

Remember, a branch is just a label on a commit, nothing more. It's a 41-byte file, containing a SHA1 hash name of a commit and a linefeed.

Sign up to request clarification or add additional context in comments.

6 Comments

Or even git checkout -b my-branch origin/some-branch^{commit}
What commit? I'm asking about branches, not commits... @jthill - doesn't that just specify a specific entry commit for the tracking branch? I don't want to track that branch at all.
A branch or a remote branch is just a label on a commit. If you set up a new branch referring to those, tracking is set up. If you refer to the commit directly, the new branch won't track any remote one.
"It's a 41-byte file, containing a SHA1 hash name of a commit and a linefeed." Which is exactly why you should not worry about "However, this leaves me with an extra local copy of some-branch."
@SzG don't actually know :-) edit wait, I think I do -- get yourself on another SE site. I added Programmers for another git question around then.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.