Git Cheatsheet

ADVERTISEMENT

GIT CHEATSHEET
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, modified files. Current branch.
Set the name that will be attached to your commits and tags.
the terminal:
$ git config --global user.email "you@example.com"
$ 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
at
$ git add [file]
$ git init [project name]
Add a file to the staging area. Use . instead of full file path, to add all
4. GIT BRANCHING MODEL
changes files 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 file back from staging area to working directory.
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 file from working directory and add deletion to staging area.
Switch working directory to the specified branch. With -b: Git will create the
$ cat .gitignore
specified branch if it does not exist.
$ git stash
/logs/*
$ git merge [from name]
!logs/.gitkeep
Put your current changes into stash.
/tmp
Join specified [from name] branch into your current branch (the one you are
$ git stash pop
*.swp
on currenlty).
Apply stored stash content into working directory, and clear stash.
Thanks to this file Git will ignore all files in logs directory (excluding
$ git branch -d [name]
the .gitkeep file), whole tmp directory and all files *.swp. Described file
$ 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.
file is placed.
-d forces deletion.
GitLab - Everyone can contribute
v1.0.1

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 2