1. GIT CONFIGURATION
3. DAY-TO-DAY WORK
A. GIT INSTALLATION
For GNU/Linux distributions Git should be available in the standard
$ git config --global user.name "Your Name"
$ git status
system repository. For example in Debian/Ubuntu please type in
See the status of your work. New, staged, modiﬁed ﬁles. Current branch.
Set the name that will be attached to your commits and tags.
$ git config --global user.email "firstname.lastname@example.org"
$ git diff [file]
$ sudo apt-get install git
Set the e-mail address that will be attached to your commits and tags.
Show changes between working directory and staging area.
If you want or need to install Git from source, you can get it from
$ git diff --staged [file]
$ git config --global color.ui auto
Shows changes in the staging area that haven't been commited.
Enable some colorization of Git output.
$ git checkout -- [file]
An excellent Git course can be found in the great Pro Git book by
2. STARTING A PROJECT
Discard changes in working directory. This operation is unrecoverable.
Scott Chacon and Ben Straub. The book is available online for free
$ git add [file]
$ git init [project name]
Add a ﬁle to the staging area. Use . instead of full ﬁle path, to add all
4. GIT BRANCHING MODEL
changes ﬁles from current directory down into directory tree.
Create new local repository. If [project name] is provided, Git will create
a new directory named [project name] and will initialize a repository inside it.
$ git reset [file]
If [project name] is not provided, then a new repository is initialized in current
$ git branch [-a]
Get ﬁle back from staging area to working directory.
List all local branches in repository. With -a: show all branches (with remote).
$ git commit [-m "message here"]
$ git clone [project url]
$ git branch [name]
Create new commit from changes added to the staging area. Commit must
Downloads a project with entire history from the remote repository.
Create new branch, referencing the current HEAD.
have a message! You can provide it by -m. Otherways $EDITOR will be opened.
B. IGNORING FILES
$ git rm [file]
$ git checkout [-b] [name]
Remove ﬁle from working directory and add deletion to staging area.
Switch working directory to the speciﬁed branch. With -b: Git will create the
$ cat .gitignore
speciﬁed branch if it does not exist.
$ git stash
$ git merge [from name]
Put your current changes into stash.
Join speciﬁed [from name] branch into your current branch (the one you are
$ git stash pop
Apply stored stash content into working directory, and clear stash.
Thanks to this ﬁle Git will ignore all ﬁles in logs directory (excluding
$ git branch -d [name]
the .gitkeep ﬁle), whole tmp directory and all ﬁles *.swp. Described ﬁle
$ git status
$ git stash drop
ignoring will work for the directory (and children directories) where .gitignore
Remove selected branch, if it is already merged into any other. -D instead of
Clear stash without applying it into working directory.
ﬁle is placed.
-d forces deletion.
GitLab - Everyone can contribute