[git] How to switch back to 'master' with git?

I have made my first commit; then created a branch (let's say branch1).

In this branch I've created a directory 'example' and commited. In GitHub I see my new branch and the new directory 'example' that I have added.

Now I wonder how can I 'sync' back to master; and so have the 'example' folder deleted (as it doesn't exist on master).

EDIT : find . -type d -empty -exec touch {}/.gitignore \; did the job.

This question is related to git

The answer is


For deleting the branch you have to stash the changes made on the branch or you need to commit the changes you made on the branch. Follow the below steps if you made any changes in the current branch.

  1. git stash or git commit -m "XXX"
  2. git checkout master
  3. git branch -D merchantApi

Note: Above steps will delete the branch locally.


Will take you to the master branch.

git checkout master

To switch to other branches do (ignore the square brackets, it's just for emphasis purposes)

git checkout [the name of the branch you want to switch to]

To create a new branch use the -b like this (ignore the square brackets, it's just for emphasis purposes)

git checkout -b [the name of the branch you want to create]


I'm trying to sort of get my head around what's going on over there. Is there anything IN your "example" folder? Git doesn't track empty folders.

If you branched and switched to your new branch then made a new folder and left it empty, and then did "git commit -a", you wouldn't get that new folder in the commit.

Which means it's untracked, which means checking out a different branch wouldn't remove it.


According to the Git Cheatsheet you have to create the branch first

git branch [branchName]

and then

git checkout [branchName]