Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - Create a new remote branch out of an old commit

Tags:

git

branch

commit

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.

like image 432
Taru Avatar asked Jul 18 '14 20:07

Taru


People also ask

How do I create a new git branch from an old commit?

In order to create a Git branch from a commit, use the “git checkout” command with the “-b” option and specify the branch name as well as the commit to create your branch from. Alternatively, you can use the “git branch” command with the branch name and the commit SHA for the new branch.

How do I create a new branch with an existing change?

Using the git checkout Command The git checkout -b <BranchName> command will create a new branch and switch to it. Moreover, this command will leave the current branch as it is and bring all uncommitted changes to the new branch. There is no local change on the master branch, as we can see in the output.

How do you checkout a previous commit in a branch?

To pull up a list of your commits and their associated hashes, you can run the git log command. To checkout a previous commit, you will use the Git checkout command followed by the commit hash you retrieved from your Git log.


1 Answers

git checkout -b new_branch_name
git reset --hard <old_commit_id>
git push origin new_branch_name
like image 120
infused Avatar answered Oct 17 '22 10:10

infused