# info > GITTUTORIAL

---
type: CommandReference
command: gittutorial
mode: man
section: 7
source: man-pages
---

## Quick Reference
- `git config --global user.name "..."` and `git config --global user.email ...` — set identity
- `git init` — create a new repository
- `git add .` — stage all files for the initial commit
- `git commit -m "message"` — commit staged changes
- `git log -p` — view commit history with diffs
- `git branch <name>` / `git switch <name>` — create and switch branches
- `git merge <branch>` — merge branch into current branch
- `git clone <url>` — clone a remote repository

## Name
gittutorial - A tutorial introduction to Git

## Synopsis
git *

## Examples

### Setting Up Identity
Introduce yourself before any operations:
shell
git config --global user.name "Your Name Comes Here"
git config --global user.email you@yourdomain.example.com
### Importing a New Project
Place a tarball under Git revision control:
shell
tar xzf project.tar.gz
cd project
git init
git add .
git commit -m "Initial commit"
`git add .` takes a snapshot of all files and stages them in the index; `git commit` stores that snapshot permanently.

### Making Changes
Modify files, stage them, review, and commit:
shell
git add file1 file2 file3
git diff --cached            # shows staged changes
git status                   # summary of current state
git commit -m "Update files"
To commit all modified (but not new) files in one step:
shell
git commit -a
Commit messages: a short title line (≤50 chars), blank line, then a detailed description. The title is used throughout Git (e.g., in `git format-patch`).

Git tracks content, not files: `git add` works both for new and modified files, staging a snapshot of the content.

### Viewing History
shell
git log                      # list commits
git log -p                   # show full diffs
git log --stat --summary     # overview of changes
### Branching and Merging
shell
git branch experimental      # create a new branch
git branch                   # list branches (* marks current)
git switch experimental      # switch to branch
# edit files, then:
git commit -a
git switch master            # back to master
git merge experimental       # merge changes from experimental
git branch -d experimental   # delete branch (safe, only if merged)
If a merge produces conflicts, edit the files to resolve, then:
shell
git commit -a
To force-delete an unmerged branch:
shell
git branch -D crazy-idea
Graphical history viewer:
shell
gitk
### Collaboration
Clone a repository:
shell
git clone /home/alice/project myrepo
Bob makes changes and commits; Alice pulls from Bob:
shell
cd /home/alice/project
git pull /home/bob/myrepo master
`git pull` fetches and merges. Before pulling, commit local changes to avoid interference. To inspect changes without merging, use `fetch`:
shell
git fetch /home/bob/myrepo master
git log -p HEAD..FETCH_HEAD   # show new commits reachable from FETCH_HEAD
gitk HEAD..FETCH_HEAD         # visualise the same
gitk HEAD...FETCH_HEAD        # commits from either side, excluding common
To use a shorthand for the remote repository:
shell
git remote add bob /home/bob/myrepo
git fetch bob                 # stores in remote-tracking branch bob/master
git log -p master..bob/master
git merge bob/master
# or directly:
git pull . remotes/bob/master
Bob can later pull Alice’s changes with simply `git pull` (Git remembers the origin URL). The clone also sets up `origin/master`:
shell
git branch -r
Cloning over ssh:
shell
git clone alice.org:/home/alice/project myrepo
### Exploring History
Each commit has a unique SHA-1 name. View details:
shell
git show c82a22c39cbc32576f64f5c6b3f24b99ea8149c7
git show c82a22c39c          # enough unique prefix
git show HEAD
git show experimental
Parent commits:
shell
git show HEAD^               # parent
git show HEAD^^              # grandparent
git show HEAD~4              # great-great grandparent
git show HEAD^1              # first parent (same as HEAD^)
git show HEAD^2              # second parent (for merge commits)
Tagging:
shell
git tag v2.5 1b2e1d63ff      # name a commit
git tag -a v2.5 -m "Release" # create annotated tag (recommended for sharing)
Using tags and references:
shell
git diff v2.5 HEAD
git branch stable v2.5
git reset --hard HEAD^        # CAUTION: discards commits and changes
`git reset` on a shared branch forces needless merges; use `git revert` instead for public history.

Searching:
shell
git grep "hello" v2.5         # all occurrences in version v2.5
git grep "hello"              # search only tracked files in working directory
Commit ranges:
shell
git log v2.5..v2.6            # commits between tags
git log v2.5..                # commits since v2.5
git log --since="2 weeks ago" # commits from last 2 weeks
git log v2.5.. Makefile       # commits touching a file
git log stable..master        # commits in master not in stable
git log master..stable        # commits in stable not in master
File versions:
shell
git diff v2.5:Makefile HEAD:Makefile.in
git show v2.5:Makefile
Graphical log with file filter:
shell
gitk --since="2 weeks ago" drivers/
## See Also
- [gittutorial-2(7)](http://localhost/phpMan.php/man/gittutorial-2/7/markdown)
- [gitcvs-migration(7)](http://localhost/phpMan.php/man/gitcvs-migration/7/markdown)
- [gitcore-tutorial(7)](http://localhost/phpMan.php/man/gitcore-tutorial/7/markdown)
- [gitglossary(7)](http://localhost/phpMan.php/man/gitglossary/7/markdown)
- [githelp(1)](http://localhost/phpMan.php/man/githelp/1/markdown) (note: man page is `git-help`)
- [gitworkflows(7)](http://localhost/phpMan.php/man/gitworkflows/7/markdown)
- [giteveryday(7)](http://localhost/phpMan.php/man/giteveryday/7/markdown)
- [The Git User’s Manual](file:///usr/share/doc/git/html/user-manual.html)