Git
Git is a version control system
Used for keeping track of changes to code
Git is a version control system
Used for keeping track of changes to code
Create a file in a directory
$ mkdir hello
$ cd hello
$ echo '# Hello' > README.md
$ ls
README.md
$ cat README.md
# Hello
Initialize a Git repository
$ git init
Initialized empty Git repository in /Users/pbarry/dev/hello/.git/
Note that the repository is stored in a hidden directory called .git
Use git status to view the state of your working directory compared to your repository
$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# README.md
nothing added to commit but untracked files present (use "git add" to track)
$ git add README.md
That change is staged, but not commited
$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: README.md
#
Use git commit
$ git commit -m 'First commit!'
[master (root-commit) b4d2429] First commit!
1 file changed, 1 insertion(+)
create mode 100644 README.md
View your changes with git log
$ git log
commit b4d2429f0b1b77393824472feaf68a4cec3147d5
Author: Paul Barry <mail@paulbarry.com>
Date: Thu Sep 19 12:02:04 2013 -0400
First commit!
$ echo 'Goodbye' > README.md
$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: README.md
#
no changes added to commit (use "git add" and/or "git commit -a")
See what changed
$ git diff
diff --git a/README.md b/README.md
index fec5601..2b60207 100644
--- a/README.md
+++ b/README.md
@@ -1 +1 @@
-# Hello
+Goodbye
$ git add README.md
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: README.md
#
$ git config --global core.editor 'atom -w'
$ git commit
[master 7e9d0c2] Made some changes
1 file changed, 1 insertion(+), 1 deletion(-)
Working directory is now clean
$ git status
# On branch master
nothing to commit, working directory clean
View commits
$ git log
commit 7e9d0c212c11965d9a4d1be391d8dc76441b595d
Author: Paul Barry <mail@paulbarry.com>
Date: Thu Sep 19 14:20:56 2013 -0400
Made some changes
commit b4d2429f0b1b77393824472feaf68a4cec3147d5
Author: Paul Barry <mail@paulbarry.com>
Date: Thu Sep 19 12:02:04 2013 -0400
First commit!
Use revert to undo changes
$ git revert 7e9d0c212c11965d9a4d1be391d8dc76441b595d
[master fe537d4] Revert "Made some changes"
1 file changed, 1 insertion(+), 1 deletion(-)
A new commit that undid the changes was created
$ git log
commit fe537d47dbbe59653c130843ae0c5c0d65021fc9
Author: Paul Barry <mail@paulbarry.com>
Date: Thu Sep 19 14:24:28 2013 -0400
Revert "Made some changes"
This reverts commit 7e9d0c212c11965d9a4d1be391d8dc76441b595d.
commit 7e9d0c212c11965d9a4d1be391d8dc76441b595d
Author: Paul Barry <mail@paulbarry.com>
Date: Thu Sep 19 14:20:56 2013 -0400
Made some changes
...
A website that hosts git repositories