Git Fundamentals

Source Control Management (

Git Fundamentals

by Nevcan Uludaş

Hands on the orange typewriter in a park
© Nevcan Uludaş



Who needs GIT?


Why GIT?

Save Time, Work Offline, Branching Capabilities, Low Budget

Quick Start

Starting a Project

			$ git clone remote_url
			$ git init (This command generates hidden .git folder.
Git keeps all of its information in one place)
$ git init directory_name
GIT init


			$ git config --global "Nevcan Uludaş"
			$ git config --global ""
			$ git config -l or --list
			$ git config "status -s"
			$ git config --global "status -s"
Git Work System
Copyright © 2017 fedeveloper

File Status Lifecycle

File Status Lifecycle


			$ git status --long
			Give the output in the long-format. This is the  default 
			$ git status -s or --short
			Give the output in the short-format
			$ git status --porcelain
			Give the output in an easy-to-parse format for scripts. This is similar to the short output, but will remain stable across Git versions and regardless of user configuration

Adding Things to Staging Area (1/2)

			$ git add file_name
			$ git add -A or --all
			Add changes from all tracked and untracked files
			$ git add .
			Stages new and modified, without deleted
			$ git add -u or --update
			Stages modified and deleted, without new

Adding Things to Staging Area (2/2)

			$ git add *
			Add all unstaged files
			$ git add *.js
			Add all unstaged JS files in current directory
			$ git add **/*.js
			Add all unstaged JS files in child directories
			$ git add ./\*.js
			Add all unstaged JS files

Resetting Things (1/2)

			$ git reset file_name
			Take files back from staging area to working area


Resetting Things (2/2)

			$ git reset --soft HEAD
			$ git reset --mixed HEAD
			$ git reset --hard HEAD

Discard Changes

			$ git reset --hard HEAD

Git Ignore (1/2)

For global ignoring add file names in .gitignore

			*.js or ./\*.js

Important! You have to PUSH this .gitignore file!

Git Ignore (2/2)

For local ignoring add file names in .git/info/exclude
* if you have already changed file, run the following code;

				$ git update-index --assume-unchanged file_name
				$ git update-index --no-assume-unchanged file_name

Golden Rule of Version Control

Only Commit RELATED Changes!


			$ git commit -m "Your commit subject"
			$ git commit --amend -m "Edited commit subject"
In case of fire

Commit Subject (1/2)

You can include keywords in your pull request titles and descriptions, as well as commit messages, to automatically close issues in GitHub.

The following keywords, followed by an issue number, will close the issue: close, closes, closed, fix, fixes, fixed, resolve, resolves, resolved.

Example: fixed #54

			$ git commit -m "[fixed #issue_id] Your commit message"

Commit Subject (2/2)

GitHub - Commit message guidelines
How to Write a Git Commit Message


Setting a Remote Repo Up

			$ git remote -v
			$ git remote add remote_name remote_url
			$ git remote remove remote_name
			$ git remote rename old_name new_name
			remote_name is usually preferred as " origin ".

Push Changes

			$ git push -u (or --set-upstream) origin master
			Track remote branches by local branches
			$ git remote show origin
			Shows all branches (local & remote) tracking and status info

Important! You always PULL before PUSH

Pull Changes

			$ git pull origin master
			You have all changes on your working area

Fetch Changes

			$ git fetch origin master
			Your working area does not change. You only can see your teammates changes with FETCH command.

Merging Types

			Merge Commit (merge bubble)
Merge conflict

Stash (1/2)

			$ git stash save "Your stash subject"
			Puts all changed files into stash
			$ git stash list
			Lists all stashes
			$ git stash apply stash@{n}
			Applies chosen stash

Stash (2/2)

			$ git shash pop
			Applies first stash and deletes it
			$ git stash drop stash@{n}
			Deletes chosen stash
			$ git stash clear
			Deletes all saved stashes
Git Basic Commands
Copyright © 2017 fedeveloper

Commit History (log) (1/3)

				$ git log 
				$ git log -2
				$ git log file_name
				$ git log branch_name
				$ git log --pretty=oneline | short | full
				$ git log --pretty=format:"%cn" | %s | %h
				$ git log --pretty=format:"%h %s" --graph

Commit History (log) (2/3)

				$ git log --since="2 weeks ago"
				$ git log --until="yesterday"
				$ git log --author="Nevcan"
				$ git log --reflog
				Shows all history

Commit History (log) (3/3)

			$ git config --global alias.lg 
"log --pretty='%Cred%h%Creset | %C(yellow)%d%Creset %s
%Cgreen(%cr)%Creset %C(cyan)[%an]%Creset' --graph"
Git lg


Diff cmd shows difference between working area and local repo

			$ git diff
			Shows all changes in all files
			$ git diff file_name
			Shows all changes in specify file
			$ git diff branch_name
			Shows all changes in specify branch


Show cmd shows difference between local repo and remote repo

			$ git show
			Shows all changes in all files
			$ git show file_name
			Shows all changes in specify file
			$ git show branch_name
			Shows all changes in specify branch

Git Branch

Why you need branches?

Git Branch
© Nevcan Uludaş


			$ git branch branch_name
			Creates a local branch
			$ git checkout branch_name
			Goes that local branch
			$ git branch --list
			Shows all local branches
			$ git branch -a or --all
			Shows all local and remote branches

Remote Branches

Creating Remote Branches
			$ git push remote_name branch_name
			$ git push origin local_branch_name:remote_branch_name

Deleting Remote Branches
			$ git push origin --delete branch_name
			$ git remote show origin

Merging vs. Rebasing

The golden rule of git rebase is to never use it on public branches.

merge rebase


			$ git tag tag_name
			Creating a tag
			$ git tag -a v1.2 -m "in v1.2 we add super cool features"
			Creating an annotated tag
			$ git tag or -l "v1*"
			Lists all tags or the spesific named tags
			$ git show tag_name

Sharing Tags

			$ git push origin tag_name

Checking Out Tags

			$ git checkout tag_name

What is HEAD?

Git Objects


© Nevcan Uludaş

Git Objects

Git is a content-addressable filesystem. It means that at the core of Git is a simple key-value data store. You can insert any kind of content into it, and it will give you back a key that you can use to retrieve the content again at any time.

Web Tools

Remote Repositories & GUI Tools

Web Tools
© Nevcan Uludaş

GUI Tools

GUI Tools Platform Price
SourceTree Windows, Mac Free for 5 users
GitHub Desktop Windows, Mac Free
TortoiseGit Windows Free
GitKraken Windows, Mac, Linux Free for non-commercial use
SmartGit Windows, Mac, Linux $79/user - Free for non-commercial use
gitg Windows, Linux Free
git-cola Windows, Mac, Linux Free
Cycligent Git Tool Windows, Mac, Linux Free
GitEye Windows, Mac, Linux Free
GitAhead Windows, Mac, Linux $29/user (Free 15 day trial)

Remote Repositories

Remote Repos Price
GitHub $7 per month for Developers (for private repos)
Bitbucket Free for up to 5 users
GitLab Free
Cloud Source by Google $1 per project-user over 5 project-users per month
AWS CodeCommit Free for up to 5 users
GitKraken $49/yr per user (free for the first two weeks)
Beanstalk $15 per month (free for the first two weeks)
FogBugz Kiln/DevHub $50 per month (up to 5 users)
SourceForge -
Apache Allura -

Git != GitHub

Fork & Pull Request

GitHub Fork & Pull Request

.md is markdown. is used to generate the html summary you see at the bottom of projects.


Nice to look up

Tenor GIF

Any Question?

Git Master

Don't forget to give a star to my repo!

Star me on GitHub!

Nevcan Uludaş

Thank You :)