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 8114203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:04:51+00:00 2026-06-06T03:04:51+00:00

I basically want to do: git checkout branchA git checkout -b branchB <commit_id> which

  • 0

I basically want to do:

git checkout branchA
git checkout -b branchB <commit_id>

which creates the new branchB branch from <commit_id> on branchA.

Question:

I’m getting into details here but the reason I’m asking is to help understand how git history works and to save a bit of typing. (the command above could of been four commands instead of two…) How do I get it to one with native git functions? Question:

Is there an easier/one line way of doing the same as above?

I was thinking of simply doing git checkout -b branchB <commit_id> but if I’m in branchC that probably won’t work cause the log/history of branchC might not be the same as branchA.

Background:

My intension for this specific situation would be to quickly revert to a previous commit in case a bug was introduced to production. I however still want to keep my new code and then discard of the new branch one the old code was pushed back to the server.

  • 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-06-06T03:04:52+00:00Added an answer on June 6, 2026 at 3:04 am

    Just

    git checkout -b branchB <commit>
    

    The hash of the commit is unique within the whole repository, thus there is no reason to change to branchA before, because the result is completely the same.

    Also this is just a shortcut for

    git checkout <commit>
    git branch branchB
    git checkout branchB
    

    As you can see the first command is a normal checkout, that will supersede your git checkout branchA anyway.

    I was thinking of simply doing git checkout -b branchB <commit_id> but if I’m in branchC that probably won’t work cause the log/history of branchC might not be the same as branchA.

    There is only one history in one repository.

    My intension for this specific situation would be to quickly revert to a previous commit in case a bug was introduced to production. I however still want to keep my new code and then discard of the new branch one the old code was pushed back to the server.

    Sounds like tags 😉

    git tag -a -m "Release 1.2.3" v1.2.3
    # Deploy 1.2.3
    #something broken!
    git checkout v1.2.2
    # Deploy 1.2.2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I basically want to open a browser window from Word using VBA that does
Basically, what I want is git diff HEAD branch1 -- foo.txt > patch.txt; git
I'm new to git and I want to be able to capture the commit
Noob here.... I cloned a git and then created a new branch in it.
Is it even possible? Basically, there's a remote repository from which I pull using
I downloaded some CVS code using the checkout command from sourceforge. Now, I want
I am following the examples here http://wiki.dreamhost.com/Git Basically I want to create a git
I basically want something like: TextView Button Button . . . TextView TextView SeekBar
I basically want to setup a relationship similar to Netflix's DVD rental model. There
I basically want the same functionality as facebook, twitter and all those other infinite

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.