over 4 years ago
Remote Repositories
git remote add origin git@github.com:onenight/try_git.git
Pushing Remotely
git push -u origin master
Pulling Remotely
git pull origin master
Cloning Repository
git clone repository_url 
Differences
git diff HEAD
Add To Stage
git add file_name
Add To Last Commit
git commit --amend -m "message"
Staged Differences (stage)
git diff --staged
Resetting the Stage
git reset file_name
Resetting Commit To Stage
git reset --soft HEAD^
Resetting all changes
git reset --hard HEAD^
Undo
git checkout file_name
Branching Out
git branch branch_name
Switching Branches
git checkout branch_name
Branching & Switching
git checkout -b branch_name
Branch Clean Up
git branch -d branch_name
Removing All The Things
git rm '*.txt'
Merge Branch
git merge branch_name
Delete Branch
git branch -d branch name
Delete Branch (Force)
git branch -D branch name
Pushing Branch To Remote
git push origin branch_name
Listing All Remote Branches
git branch -r
Remote Show
git remote show origin
Deleting A Remote Branch
git push origin :branch_name
Clean Up Deleted Remote Branches
git remote prune origin
Listing Tags
git tag
Checkout Code At Tag
git checkout tag_name
Adding A New Tag
git tag -a tag_name -m "message"
Pushing Tags
git push --tags
Rebase
  1. Move all changes to master which are not in origin/master to a temporary area
  2. Run all origin/master commits
  3. Run all commits in the temporary area, one at a time

    git rebase 
    

Configuration

Colorizing The Log
git config --global color.ui true
The Log
git log
One Line Log
git log --pretty-oneline
Log Format
  • %ad - author date
  • %an - author name
  • %h - SHA hash
  • %s - subject
  • %d - ref names

    git log --pretty-format:"%h %ad- %s [%an]"
    
Patch(Showing Log Changes)
git log --oneline -p
Stats(Showing Log State)
git log --oneline --stat
Graph(Showing Log As Graph)
git log --oneline --graph
Date Ranges
git log --until=1.minute.ago
git log --since=1.day.ago
git log --since=1.hour.ago
git log --since=1.month.ago --until=2.weeks.ago
git log --since=2000-01-01 --until=2012-12-21
Uncommitted Changes
git diff HEAD
git diff HEAD^
git diff HEAD~5
git diff HEAD^..HEAD
Earlier Commits
git diff SHAs..SHAs
git diff master branch_name
Blame(Showing history of commits)
git blame file_name --date short
Excluding Files
  • Adding folder/file_name to .git/info/exclude
Excluding From All Copies
  • Adding pattern to .gitignore
Removing Files
git rm file_name
Untraching Files
git rm --cached file_name
Config
git config --global user.name "user name"
git config --global user.email "user email"

Use opendiff for merging conflicts

git config --global merge.tool opendiff
Local Config

Sets email for current repo

git config user.email
git config --list
Aliases
git config --global alias.mylog \ 
"log --pretty=format: '%h %s [%an]' --graph"

git config --global alias.lol \
"log --graph --decorate --pretty=online --abbrev-commit --all"

git config --global alias.st status

git config --global alias.co checkout

git config --global alias.br branch

git config --global alias.ci commit
What is super →
 
comments powered by Disqus