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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:03:47+00:00 2026-06-17T22:03:47+00:00

Basic question but this happens to me all the time: Make changes in a

  • 0

Basic question but this happens to me all the time:

  • Make changes in a working-branch
  • Switch to master
  • git merge working-branch
  • git push
  • cap deploy(to staging)
  • make a new cup of tea

then I come back and think of something else and start making some changes…while still on master.

What’s an easy way to either:

  1. prevent direct edits on master (warning perhaps)
  2. move all edits over to working-branch and clear master so I can continue editing on working-branch or
  3. spin edits into an entirely new branch new-working-branch and then discard working-branch?

Took a risk and tried the recommendation in the latter part of "Branches" section of this page but that just wiped out ALL my edits?! Perhaps because after git branch dubious-experiment and git checkout master the git status on both branches was identical (not ‘clean’ on master). So git reset --hard <SHA1sum> wiped out all changes on both?!

  git branch dubious-experiment

  M---N-----O----P---Q ("master" and "dubious-experiment")

  git checkout master

  # Be careful with this next command: make sure "git status" is
  # clean, you're definitely on "master" and the
  # "dubious-experiment" branch has the commits you were working
  # on first...

  git reset --hard <SHA1sum of commit N>
  • 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-17T22:03:49+00:00Added an answer on June 17, 2026 at 10:03 pm

    From your description, I assume that you did not commit any changes yet – is that correct?

    If yes, here’s your answers:

    How to prevent direct edits to master

    You would need to set that in your editor, but that will probably be difficult. Displaying your current branch in your prompt and your editor helps a lot.

    How to move the changes into a new branch new-working-branch and then discard working-branch

    git checkout -b new-working-branch
    git add …
    git commit -m "mycommit" 
    

    As you didn’t commit anything to master yet, you don’t need to change anything on master. You can now discard your working-branch if you feel like it.

    How to move the changes over to working-branch

    git checkout -b temp-branch
    git add …
    git commit -m "mycommit" 
    git rebase --onto working-branch master
    git checkout working-branch
    git reset --hard temp-branch
    git branch -d temp-branch
    

    If your changes don’t conflict with any changes that are on master, but not in working-branch, this can be done a lot simpler:

    git stash
    git checkout working-branch
    git stash pop
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may seem a basic question but my is not currently working. I am
i'm working in VC++, but this is a basic C++ question ... I am
this is a pretty basic question but I can't seem to get it right.
This might be basic question but how do I create a list of lists
This is a pretty basic question but I can't find a good answer for
This may be a basic question but how can I include a module with
This is a basic question but I am struggling to find a decent solution.
I know this should be a basic question but I am hitting a brick
Sorry if this is a really basic question but it's been really getting to
I realize this is a basic question but I have searched online, been to

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.