This document provides an introduction and overview of Git version control system. It covers:
- Git was created by Linus Torvalds to be fast and capable of handling large projects like the Linux kernel.
- Common Git commands like init, add, commit, status, diff, log are demonstrated along with basic workflows.
- Advanced topics covered include branching, merging, tagging, collaboration using remote repositories and pushing/pulling.
- The goal is to help the reader understand the basics of Git and get started using it effectively.
3. GIT origins and start-points
● Created by Linus Torvalds (created Linux as
well)
● Linux kernel project
● Meant to be
○ Fast distributed system
○ Capable of handling large projects
● Command line interface
● Official GIT site: http://git-scm.com
● There are many available GUI tools
> git help
usage: git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
[-c name=value] [--help]
<command> [<args>]Now I GIT it!!!
4. Let's GIT started
● Installation - depends on the OS
● Initial global configuration
> git config --global user.name "Bill Gates"
> git config --global user.email bill.gates@microsoft.com
> git config --global color.ui true
Now I GIT it!!!
5. Let's GIT going
● Start a new empty local repository
> mkdir NowIGitIt
> cd NowIGitIt
> git init
Initialized empty Git repository in ~/Documents/Tikal/git_demo/NowIGitIt/.git/
> git status
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)
Now I GIT it!!!
6. Common workflow - new file
Now I GIT it!!!
Step Command Output of git status command
Create file locally echo start > First.txt # On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# First.txt
nothing added to commit but untracked files present (use "git add"
to track)
Add file to staging
area
git add First.txt # On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: First.txt
#
Commit changes git commit First.txt -m "First
commit"
output of command:
master (root-commit) 30e3004] First commit
1 file changed, 1 insertion(+)
create mode 100644 First.txt
# On branch master
nothing to commit (working directory clean)
7. Common workflow - modified file
Now I GIT it!!!
Step Command Output of git status command
Change file locally echo changed > First.txt # 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: First.txt
#
no changes added to commit (use "git add" and/or "git
commit -a")
Commit changes git commit First.txt -m "Second
commit"
output of command:
[[master f1d433f] Second commit
1 file changed, 1 insertion(+), 1 deletion(-)
# On branch master
nothing to commit (working directory clean)
9. GIT log - view history
Now I GIT it!!!
> git log
commit f1d433f5b79a10b9a12dc8277bc9aae62bff0cfa
Author: Yoram Michaeli <yorammi@tikalk.com>
Date: Fri May 3 14:58:51 2013 +0300
Second commit
commit 30e30041fdb8f97751ddc3f99da25a960b6d3b74
Author: Yoram Michaeli <yorammi@tikalk.com>
Date: Fri May 3 14:41:44 2013 +0300
First commit
10. GIT diff - where things matters...
> echo change2 > First.txt
> git diff
diff --git a/First.txt b/First.txt
index 5ea2ed4..39c5733 100644
--- a/First.txt
+++ b/First.txt
@@ -1 +1 @@
-changed
+change2
Now I GIT it!!!
11. Regretting what I've done...
Now I GIT it!!!
Action Command Output of git status command
Unstaging a file git reset HEAD First.txt
output of command:
Unstaged changes after reset:
M First.txt
# 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: First.txt
#
no changes added to commit (use "git add" and/or "git
commit -a")
Discard changes git checkout -- First.txt # On branch master
nothing to commit (working directory clean)
Undoing a commit git reset --soft HEAD^ # On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: First.txt
#
13. GIT Repository clone
> git clone https://github.com/tikalk/NowIGitIt.git
● Clone an existing repository as a local
repository
● Clones into current folder
● Can be named differently than the origin
repository
Now I GIT it!!!
14. Add remote GIT repository
> git remote add origin https://github.com/tikalk/NowIGitIt.git
● Clone command add origin remote
automatically
● More than one remote is possible
● Use git remote remove <name> to remove a
remote
Now I GIT it!!!
15. Push to a remote repository
> git push -u origin master
● Push changes on local repository into a
remote repository
● Will fail if there are conflicts
● Fast-forward push is the best!
Now I GIT it!!!
16. Pull from remote repository
> git pull
● Pull changes from remote repository into the
local repository
● Will fail if there are conflicts
● Fast-forward pull is the best!
Now I GIT it!!!
19. Add GIT tag
> git tag -a tag1 -m "first tag"
> git tag -a tag2 -m "second tag"
> git tag
tag1
tag2
> git tag -d tag2
> git tag
tag1
Now I GIT it!!!
20. And if you still don't GIT it...
● Git introduction
● GIT real
● Linus talks about git
Now I GIT it!!!