Source Control Management (git-scm.com)
$ 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 config --global user.name "Nevcan Uludaş"
$ git config --global user.email "nevcan@uludas.com"
$ git config -l or --list
$ git config alias.st "status -s"
.git/config$ git config --global alias.st "status -s"
~/.gitconfig
$ 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
$ 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
$ 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
$ git reset file_name
Take files back from staging area to working area
$ git reset --soft HEAD
$ git reset --mixed HEAD
$ git reset --hard HEAD
$ git reset --hard HEAD
For global ignoring add file names in .gitignore
file_name
/folder_name
*.js or ./\*.js
Important! You have to PUSH this .gitignore file!
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
$ git commit -m "Your commit subject"
$ git commit --amend -m "Edited commit subject"
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"
$ git rebase -i origin/master~3 master
$ git push --force origin master
$ 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 ".
$ 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
$ git pull origin master
You have all changes on your working area
$ git fetch origin master
Your working area does not change. You only can see your teammates changes with FETCH command.
Fast-Forward
Merge Commit (merge bubble)
Conflict
$ 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
$ 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 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
$ git log --since="2 weeks ago"
$ git log --until="yesterday"
$ git log --author="Nevcan"
$ git log --reflog
Shows all history
$ git config --global alias.lg
"log --pretty='%Cred%h%Creset | %C(yellow)%d%Creset %s
%Cgreen(%cr)%Creset %C(cyan)[%an]%Creset' --graph"
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
Why you need branches?
$ 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
$ git push remote_name branch_name
$ git push origin local_branch_name:remote_branch_name
$ git push origin --delete branch_name
$ git remote show origin
The golden rule of git rebase is to never use it on public branches.
$ 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
$ git push origin tag_name
$ git checkout tag_name
SHA-1
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.
Remote Repositories & 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 Repos | Price |
---|---|
Azure Repo | Free for up to 5 users |
GitHub | Free |
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 | - |
.md is markdown. README.md is used to generate the html summary you see at the bottom of projects.