18

I'm using the following Git command in order to create a new remote branch:

git push origin origin:refs/heads/new_branch_name

I wish that the new branch will start from an old commit,

How can I do that? (I've tried some different methods, though failed)

Thank you.

Taru
  • 2,562
  • 4
  • 22
  • 30

3 Answers3

34
git checkout -b new_branch_name
git reset --hard <old_commit_id>
git push origin new_branch_name
infused
  • 24,000
  • 13
  • 68
  • 78
3

There is a one-liner:

git push origin <id-of-commit>:refs/heads/<name-of-remote-branch>
2

if you want create a new branch from a specific commit, execute command git log or gitk, copy the id and execute command git checkout ID COMMIT, then commit and push. This link can help you.

Community
  • 1
  • 1
  • This question is mainly about creating new *remote* branch, but thanks anyway. – Taru Jul 18 '14 at 20:50
  • When you execute command ``git checkout ID COMMIT``, and then execute ``git checkout -b NEW BRANCH`` and execute push, new remote branch is created with code from ID COMMIT selected – Alex Correa Jul 18 '14 at 22:05
  • @Taru The title, though, does not imply the `remote` part. Thanks for the question, in any case. – Nikos Alexandris Jan 08 '16 at 10:26