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.
Solution 1:
You need to checkout the branch:
git checkout master
See the Git cheat sheets for more information.
Edit: Please note that git does not manage empty directories, so you'll have to manage them yourself. If your directory is empty, just remove it directly.
Solution 2:
According to the Git Cheatsheet you have to create the branch first
git branch [branchName]
and then
git checkout [branchName]
Solution 3:
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]
Solution 4:
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.
-
git stash
orgit commit -m "XXX"
git checkout master
git branch -D merchantApi
Note: Above steps will delete the branch locally.