Skip to content

Instantly share code, notes, and snippets.

@bchase
Last active March 24, 2017 11:54
Show Gist options
  • Select an option

  • Save bchase/129746f6003bb688099fa6fe4a29c501 to your computer and use it in GitHub Desktop.

Select an option

Save bchase/129746f6003bb688099fa6fe4a29c501 to your computer and use it in GitHub Desktop.

new Git project

dev $ mkdir proj && cd proj

proj $ git init
Initialized empty Git repository in /home/bosco/dev/proj/.git/

create and commit a file

proj [master] $ touch foo

proj [master X] $  git add foo && git commit foo -m 'initial commit'
[master (root-commit) d0d32a9] initial commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 foo

cut a new branch, then change and commit the file

proj [master] $ git checkout -b other-branch
Switched to a new branch 'other-branch'

proj [other-branch] $ echo change > foo

proj [other-branch X] $ git commit foo -m 'change foo'
[other-branch 302476c] change foo
 1 file changed, 1 insertion(+)

checkout master (now one commit behind other-branch)

proj [other-branch] $ git checkout master
Switched to branch 'master'

change the file to something different from other-branch without committing

proj [master] $ echo different-change > foo

attempt to check out other-branch

proj [master X] $ git checkout other-branch
error: Your local changes to the following files would be overwritten by checkout:
	foo
Please, commit your changes or stash them before you can switch branches.
Aborting

clear changes, then create a file, and checkout other-branch

proj [master X] $ git checkout -- foo

proj [master] $  touch bar

proj [master X] $ git status -s
?? bar

proj [master X] $ git checkout other-branch

Switched to branch 'other-branch'
proj [other-branch X] $ git status -s
?? bar

start project

dev $ mkdir proj && cd proj && git init
Initialized empty Git repository in /home/bosco/dev/proj/.git/

create app and commit it to master

proj [master] $ touch app && git add app && git commit app -m 'v1.0'
[master (root-commit) a271985] v1.0
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 app

start on experimental changes to app without committing

proj [master] $ echo "experimental v1.1a changes" > app

decide not to pollute master with experimental changes, so cut new branch

proj [master X] $ git checkout -b v1.1
M	app
Switched to a new branch 'v1.1'

proj [v1.1 X] $ git status -s
M app

commit experimental-feature2 on feature2 branch

proj [v1.1 X] $ git commit app -m 'start work on v1.1'
[v1.1 d039c3d] start work on v1.1
 1 file changed, 1 insertion(+)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment