Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 336533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:15:05+00:00 2026-05-12T10:15:05+00:00

Usually I work on the master branch, and I make some commits, and push

  • 0

Usually I work on the master branch, and I make some commits, and push it.

Then I also need to push these commits to other branch.

So usually, I will do:

$ git checkout another-branch
$ git cherry-pick commit1
$ git cherry-pick commit2
...
$ git cherry-pick commitn
$ git push

Some kind of stupid, is there anyway I can merge some commits from the head of the master branch so I need not
bother to cherry-pick one by one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T10:15:06+00:00Added an answer on May 12, 2026 at 10:15 am

    It sounds like you might want to make those commits on a branch other than master, and then merge that branch to both master and your second branch:

    git checkout working-branch
    <do some work>
    git commit
    git checkout master
    git merge working-branch
    git checkout second-branch
    git merge working-branch
    

    This is much, much better than cherry-picking because it doesn’t involve duplicating commits in the history, gets rid of any issues about cherry-picking a commit twice (which you currently must manually avoid)…and is just the way git is designed to work. I don’t know what your second branch is, but what I’m describing is essentially the common workflow of periodically merging maintenance and topic branches back into master as well as any other appropriate modified-release or maintenance branches.

    I strongly recommend that you adopt a workflow where this is done by merging as I described above, but to answer the question you asked, if you absolutely must work on master and cherry-pick, you might want to write yourself a little script, something like:

    #!/bin/bash
    # take two arguments:
    # 1. other branch to put commits on
    # 2. number of commits to cherry-pick from master    
    
    if ! git checkout $1; then
        exit
    fi
    git rev-list --reverse -n $2 master |
    while read commit; do
        if ! git cherry-pick $commit; then
            exit
        fi
    done
    

    Obviously there are ways to make the script more robust, e.g. adding the ability to resume after cherry-picks whose patches don’t apply properly, but it’s a start.

    You can mess around with the way you use git-rev-list to select the commits, of course. You could even pass all but the first argument along to git-rev-list, so that you could do cherries-pick <branch> -n 5 master or cherries-pick <branch> release_tag..master or whatever you want. Have a look at its man page!

    You can also use git-rebase as was suggested elsewhere, but because you don’t actually want to move master, you’ll end up doing something like this:

    git branch master-copy master
    git rebase --onto <branch> master~5 master
    git checkout <branch>
    git merge master-copy
    git branch -d master-copy
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I usually create a feature branch in git, work on it, then merge
I usually work on my Master branch, and push to Production. I accidentally worked
I usually work with PHP so sadly don't have some basic JS principles down.
I usually test my code locally on my work machine and then move it
I work with Mac OS X Leopard. I usually have 5 or 10 text
I work on a project that takes 2-3 minuts to compile. Usually when I
I'm working on a C# windows program with Visual Studio 2008. Usually, I work
Usually I worked with PostgreSQL and never had a problem, but now I need
I'm trying to put some simple jQuery code into the Wordpress header (usually just
Usually work in Windows, but trying to setup RabbitMQ on my Mac. Can someone

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.