Switching back to master branch to work in isolated env

I’m in master branch.

  1. git checout -b new-branch
  2. mkdir new-branch-stuff
  3. cd new-branch-stuff
  4. echo "new stuff here" >> stuff.txt
  5. git add stuff.txt

Then at this point I decide that I have to work on something else (since my boss asked me to work on something urgent). So I’m going to switch back on master branch

  • Is it best practice to place Java project directly under the Source Code Repository
  • git fetch: Cannot allocate memory
  • remove waiting push in sourcetree
  • Best practice for translating git versioned documents
  • git error: inflate: data stream error (incorrect data check) after download was done
  • Add a line to the git commit message while I'm editing code
    1. checkout master
    2. git status

    I can see this, which is from my new-branch where I’ve supposed to switch from

    % git checkout master
    A    ..new-branch-stuff/stuff.txt
    

    What I expect is not to see my old branch-specific files. Because I want be in master isolated environment to be save knowing what I’m about to change on that current branch.

    Q: What is the way git would suggest to go about this?

    (I’m kind of new in git.. still. Trying to get my head around proper working with branches)

  • How to change the main branch in BitBucket?
  • Cannot find git while installing foundation
  • How to work with other person on one branch in Git?
  • Running a HTML/PHP/JS project from GitHub on Cloud9 (c9.io) IDE
  • Should I keep the feature branches or delete them after merge them into release?
  • How to customize diff git to ignore yard date generation
  • One Solution collect form web for “Switching back to master branch to work in isolated env”

    You have not yet done a git commit.

    The git checkout -b created the new branch and put you on it. But that’s all it did.

    Any time you do a git add, changes you have become staged to go into the next commit. (Changes you have that have not been git added are not-yet-staged.) But in any case, you have not made a commit.

    Then, you said git checkout master. Git made sure that switching from branch new-branch to master would not lose anything (it won’t, in this case) so it switched from branch new-branch back to master.

    The change you staged, git add stuff.txt, is still staged for the next commit. You haven’t made a commit yet, so it comes with you into branch master.

    If you wish to save it away on the new branch, first switch back, then commit:

    • use git checkout new-branch to get back to new-branch
    • at any time, use git status and/or git diff --cached to see what you will commit
    • at any time, use git diff to see what you won’t commit
    • at any time, use git commit to commit it, on whatever branch you are on right then.
    Git Baby is a git and github fan, let's start git clone.