Skip to main content.

5.1.8. An Introduction to git

git basics


introduce yourself:

$ git config --global "Your Name Comes Here"
$ git config --global

Create a new repository

$ git-init-db
$ git-add .
$ git-commit

Working with existing repositories

Best practice: work on a branch and leave master branch unmodified (track upstream)

clone a repository:

$ git-clone git://

look at the history

$ git-log     # simple
$ tig         # tui

add a branch for hacking

$ git-checkout -b hacking HEAD

edit some files and look at changes in working dir

$ git diff

add modified files to the index:

$ git add file1 file2

delete some and mark them as deleted:

$ git rm file3

look at diffs of the modified files added to the index

$ git diff --cached

get some general statistics of which files were modified:

$ git status

to throw away the changes git reset HEAD, to reset the working directory git-checkout -f

commit the changes added to the index (will be prompted for commit message)

$ git commit    # -s adds Signed-off-by: ... line

alternatively without using the index as an intermediate stage:

$ git commit -a

unhappy with commit message?

$ git commit --amend

local branches

what branches have we got?

git branch

create a branch as a clone of the current branch:

$ git branch hacking

check out the contents of this branch:

git checkout hacking

hack around, make a mess of it and decide to throw it away

git checkout -f
git checkout master
git branch -d hacking

git for developers

Example: rework last 5 commits

$ git-rebase --interactive HEAD~5

move around lines and change pick into squash in order to merge commit into previous one.

$ git rebase --abort


5.1.7. Linux kernel / Linux device drivers resources 1. Denx Training Topics 5.1.9. Linux source code organisation
Prev Home Next