Git version control system

Links

Manual pages for git

About blobs and trees

Starting a new project with git

Wat wil je in eerste instantie met GIT ?
- nieuwe (local) repository maken voor nieuw of bestaand single user project
- nieuwe (remote) repository maken voor nieuw of bestaand multi user project
- local files toevoegen/commit/checkout
- remote files toevoegen/commit/checkout
- verschillen bekijken tussen files/local/remote
- deelnemen aan bestaand project of bestaand project naar je toe halen:
  uit remote repository of kopie maken van repository (clone), daar lokaal
  mee verder werken en veranderingen terugsturen (push)
- branch/merge
- files toevoegen/weghalen/verplaatsen

Primary set of git commands

       git-clone
           Clone a repository into a new directory.

       git-init
           Create an empty git repository or reinitialize an existing one.

git-log Show commit logs. git-add Add file contents to the index. git-commit Record changes to the repository. git-checkout Checkout a branch or paths to the working tree. git-diff Show changes between commits, commit and working tree, etc. git-status Show the working tree status.
git-diff-files Compares files in the working tree and the index. git-diff-index Compares content and mode of blobs between the index and repository. git-diff-tree Compares the content and mode of blobs found via two tree objects. git-ls-files Show information about files in the index and the working tree. git-ls-tree List the contents of a tree object.

Secondary set of git commands

       git-branch
           List, create, or delete branches.

       git-merge
           Join two or more development histories together.

git-mv Move or rename a file, a directory, or a symlink.
git-pull Fetch from and merge with another repository or a local branch. git-push Update remote refs along with associated objects. git-fetch Download objects and refs from another repository.
git-reset Reset current HEAD to the specified state. git-tag ?

Getting started with a local repository

Local repository:
git init
 * Initialized empty Git repository
 * you'll find a .git directory in the top level directory of your project

git add <some files>

git status (shows staged, unstaged, untracked files)
git status -s (short)

git commit

En nu bekijken wat we in repository gezet hebben:
git status
git ls-tree HEAD
git show (--name-only)


Make modifications Eerst verschillen bekijken: git status -s git ls-tree HEAD git show (--name-only) git commit doet nog niks als we niet eerst git add doen git log git show (--name-only) git show <a specific commit or HEAD>
git add . (add everything to the index) git commit (commits all files in the index) OR git commit -a (adds everything to the index and commits the index) make modifications, then git diff git add <files> git commit git diff
git add --patch lets you select the areas that have changed

Tracking the history


Various ways to diff:


$ git diff          # difference between the index file and your
                    # working directory; changes that would not
                    # be included if you ran "commit" now.

$ git diff --cached # difference between HEAD and the index; what
                    # would be committed if you ran "commit" now.

$ git diff HEAD     # difference between HEAD and working tree; what
                    # would be committed if you ran "commit -a" now.

$ git diff <commit>     # difference between a specific commit and working tree

$ git status        # a brief per-file summary of the above.

The most recent commit in the currently checked-out branch can always be
referred to as HEAD, and the "parent" of any commit can always be referred
to by appending a caret, "^", to the end of the name of the commit.

HEAD~n can refer to the nth previous commit

Examples:
git diff HEAD^:jack_flanger.cpp HEAD^^:jack_flanger.cpp 
git diff HEAD~3:jack_flanger.cpp HEAD~4:jack_flanger.cpp
git checkout master~2 jack_flanger.cpp

#
# since/until
#
 git log --since="1 week ago"
 2077  git log --until="1 week ago"


git ls-files  --+ shows a list of (managed ?) files

git ls-files -- stage  --+ shows a list of staged files

git add path/to/new/file

git whatchanged  --+ geeft history
If you also want to see complete diffs at each step, use
git whatchanged -p

Stay happy: use the stash

git reflog

Add your working directory and index to the stash on a daily basis
git stash

git reflog expire --expire=30.days refs/stash

Graphic user interfaces

gitk - GUI for GIT
gitg - (Gnome) GUI for GIT
git-gui - GUI for GIT (weetikveel)

Working with branches

Using and/or creating a remote repository

keys
ssh-keygen

git fetch
git pull
git push
git ls-remote


e.g. github


Remote (shared) repository
git init --bare

GIT over SSH or proprietary GIT protocol
git clone ssh://yourhost/~you/repository

git push ssh://yourserver.com/~you/proj.git master:master
  OR
git push ssh://yourserver.com/~you/proj.git master


Bare repository: a repository that only includes the files/folders inside of
the .git directory non-bare repository.
A normal clone, has a working directory with checked out files.

The best practice is when you want to push changes, don’t push to a
non-bare repository. If you’re going to push changes, make a bare repository
clone with git clone --bare

Op client:
git remote add  @:

push local tree to server:
git push  [branch]