Skip to main content

Git

https://git-scm.com/

Git is a distributed version control system.

Cheat Sheet

Visual Cheat Sheet

Commands

Git Reference

Clone

https://git-scm.com/docs/git-clone

Clone a repository into a new directory

git clone <repository>

Fetch

https://git-scm.com/docs/git-fetch

Download objects and refs from another repository. Use git fetch to update the branch listing for a repository.

Use the --all flag to fetch all remote objects.

Use the --prune flag to remove any remote-tracking references that no longer exist on the remote.

git fetch --all --prune

Pull

https://git-scm.com/docs/git-pull

Use git pull to update the current branch.

git pull [<options>] [<repository> [<refspec>…​]]

Add

https://git-scm.com/docs/git-add

Stage a file. Add file contents to the index.

git add <pathspec>

git add sample.txt
git add *.txt
git add Documentation/\*.txt

Remove

https://git-scm.com/docs/git-rm

Unstage or remove a file.

Use the --cached flag to unstage and remove paths only from the index. Working tree files, whether modified or not, will be left alone.

Use the --force flag override the up-to-date check. If a file was newly created locally, this will delete the file.

rm test.txt --cached

rm test.txt --force

Global .gitconfig

In Windows: C:\Users\<user>\.gitconfig

[filter "lfs"]
required = true
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
[user]
name = Some User
email = someuser@users.noreply.github.com

.gitignore

https://github.com/github/gitignore

Partial from https://gist.github.com/salcode/10017553

# ignore all files starting with . or ~
.*
~*

# ignore node/grunt dependency directories
node_modules/

# Ignore build directories.
/build
/dist

# ignore composer vendor directory
/vendor

# ignore OS generated files
ehthumbs.db
Thumbs.db

# ignore log files and databases
*.log
*.sql
*.sqlite

# ignore compiled files
*.com
*.class
*.dll
*.exe
*.o
*.so

# ignore packaged files
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

# ignore private/secret files
*.der
*.key
*.pem

# --------------------------------------------------------
# BEGIN Explictly Allowed Files (i.e. do NOT ignore these)
# --------------------------------------------------------

# track these files, if they exist
!.editorconfig
!.env.example
!.git-blame-ignore-revs
!.gitignore
!.nvmrc