Git Lifecycle: More on Branches

The following explains how to create a new branch. You have to be in a project to begin with.

$ cd rest-server $ git checkout -b jack

Having created two new branches after jack, named jill and harry, here's how to get rid of jill because we don't want it anymore. Most of this is done from branch harry. In square brackets: the name of the current branch.

[harry] ~/dev/rest-server> git push origin harry Counting objects: 55, done. Delta compression using up to 4 threads. Compressing objects: 100% (26/26), done. Writing objects: 100% (29/29), 3.55 KiB, done. Total 29 (delta 19), reused 0 (delta 0) To [email protected]:rest-server 5391f4d..5c098e4 harry -> harry [harry] ~/dev/rest-server> git push origin :jill To [email protected]:rest-server - [deleted] jill [harry] ~/dev/rest-server> git branch -d jill error: The branch 'jill' is not fully merged. If you are sure you want to delete it, run 'git branch -D jill'. [harry] ~/dev/rest-server> git checkout jill Switched to branch 'jill' [jill] ~/dev/rest-server> git branch -d jill error: Cannot delete the branch 'jill' which you are currently on. [jill] ~/dev/rest-server> git checkout harry Switched to branch 'harry' [harry] ~/dev/rest-server> git branch -D jill Deleted branch jill (was 0594117). [harry] ~/dev/rest-server> git checkout jill error: pathspec 'jill' did not match any file(s) known to git.

Note the sequence below as a shorthand: you can return to the previously checked-out branch using the option -:

[harry] ~/dev/rest-server> git checkout jill [jill] ~/dev/rest-server> git checkout - [harry] ~/dev/rest-server> git branch master * harry jill