10. first things first
let git know your name and email:
git config --global user.name "Your Name"
git config --global user.email "your_email@whatever.com"
11. git init
Create an empty git repository or reinitialize an existing one
$ mkdir getonwithgit
$ cd getonwithgit/
$ git init
Initialized empty Git repository in /Users/hrahman/test/getonwithgit/.git/
12. git add
(master)$ echo "Hello World" > hello.txt
(master)$ git status
# On branch master
# Initial commit
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
# hello.txt
nothing added to commit but untracked files present (use "git add" to track)
(master)$ git add hello.txt
(master)$ git status
# On branch master
# Initial commit
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
# new file: hello.txt
13. git commit
(master)$ git commit -m "first commit"
[master (root-commit) 05e96c3] first commit
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 hello.txt
(master)$ git show
commit 05e96c39452126e9310e84203af72f141c37a493
Author: Habeeb Rahman <hrahman@apigee.com>
Date: Tue Jun 18 13:46:35 2013 +0530
first commit
diff --git a/hello.txt b/hello.txt
new file mode 100644
index 0000000..557db03
--- /dev/null
+++ b/hello.txt
@@ -0,0 +1 @@
+Hello World
14. git diff
git diff: Show differences between your working directory and the
index.
git diff –cached: Show differences between the index and the
most recent commit.
git diff HEAD: Show the differences between your working
directory and the most recent commit.
15. git commit --amend
you commit and then realize you forgot to stage the changes in a file
you wanted to add to this commit:
$ git commit -m 'initial commit'
$ git add forgotten_file
$ git commit --amend
16. branch
create a new branch:
(master)$ git checkout -b dev_feature
Switched to a new branch 'dev_feature'
switch to an existing branch:
(dev_feature)$ git checkout master
Switched to branch 'master'
(dev_feature)$ echo "new feature" > feature.txt
(dev_feature)$ git add feature.txt
(dev_feature)$ git commit -m "feature"
17. branch
delete a branch
$git branch -d dev_new_branch
show all local branches:
$git branch
show all local and remote branches:
$git branch -a