Documentation

Documentation
Start with Git by reading a cheat sheet by @yablko

Git Settings

Check if you have Git installed by typing:

git --version


Set username and password (if you use Github, use github data).

git config --global user.name "yourname"

git config --global user.email "your@email.hu"

Git Basics

Activate Git for your project.

git init


Check status / see what has changed.

git status


If you make a change to a file and want it in a new version of the project, select it.

git add index.html


Carve the change into stone. Always add a brief description of the change.

git commit -m "I added index.html"


See project development.

git log

Extra Piece of Git

Mark all .png files from the images directory.

git add images/*.png


Mark all of this directory (except deleted files).

git add .


Mark all of this directory (including deleted files).

git add -A


To unmark files.

git restore --staged .


Commit all changed (not new) files.
Add a comment now.

git commit -a

git commit -am "I modified the code, and now it's good."


Simplify the log. Put it on one line.

git log --graph --decorate --abbrev-commit --all

git log --graph --decorate --abbrev-commit --all --pretty=oneline


If you save index.html but screw it up. And you want to go back to the git version.

git checkout -- index.html


You will find a hash commit via the git log. Skip the first few characters (eg c10e47f) and this way you can jump to an older version of the project.

git checkout c10e47f


Go back to the current version.

git checkout master

How to turn off VIM

- Press "i"

- Write commit comment

- Press Esc

- Write :wq

And the up / down arrows and q if the git log is close.

Remote Server

Clone the project to your directory.

git clone https://github.com/user/yourproject.git yourdirectory

Create a link to an external server (or a specific repository).

git remote add origin https://github.com/ty/link-on-your-project.git

Print changes from your computer to the server. (Enter github name / password.)

git push origin master

Upload changes from the server to your computer.

git pull origin master

Check the server for changes.

git remote update

git status

Plus or minus what changes were they?

git whatchanged origin/master -n 1

Git Branch/Merge

If you are making a bugfix, make a bugfix branch. If you are doing a new feature, make a new feature branch.

git branch bugfix

Switch to the new bugfix branch. Do your commits there.

git checkout bugfix

When you have the feature ready, switch to the main branch.

git checkout master

And merge changes from bugfix to it.

git merge bugfix

Try to read merge vs rebase article.