user265950
user265950

Reputation: 487

push a specific commit from one remote branch to another remote branch

I have 2 remote branches, dev and rls. We are working on the dev branch currently. My rls branch is empty/untouched. I want to move a specific commit(sha-1 hashes) from dev to the rls branch. Please guide me the best, safe and easy way to do the same in Git.

Thanks...

Upvotes: 1

Views: 1925

Answers (3)

joshtkling
joshtkling

Reputation: 3538

If you are looking for rls to be a snapshot of the dev branch at some arbitrary commit, you can use git reset to move your branch pointer to the commit you are looking for. Make sure you have no unstaged changes when doing this.

git checkout rls  
git reset --hard <SHA-1 of commit in dev>

Example:
If dev looks like:

A - B - C - D

and you want rls to look like:

A - B

you would do

git checkout rls
git reset --hard <sha-1 of B>

However, if you want to choose a more specific range of commits that you want to push to rls, you'll want to use the git cherry-pick command.

git checkout rls
git cherry-pick <non-inclusive-starting-SHA1>..<inclusive-ending-SHA1>

Upvotes: 1

Brad
Brad

Reputation: 5532

If you want to move all code until a specific commit to the rls branch, use git merge. For example,

git checkout rls
git merge [SHA1 of last commit you are interested in]

Upvotes: 1

VonC
VonC

Reputation: 1328602

One way would be to use git cherry-pick, in order to select the exact commits you want to report on rls branch.

See "Can anyone explain what git cherry-pick does?" for more.

Then you can push rls to the corresponding remote branch.

So:

  1. cherry-pick locally in order to have an rls local branch which looks like something you want to publish (push)
  2. push rls to the remote repo

Upvotes: 2

Related Questions