Version Control

git

Config

git always uses --global option to config for all repos.

@example git config –global user.name # Set user name git config --global user.email @@gmail.com # Set user email

git config –global http.proxy # Set proxy of http to git config --global https.proxy # Set proxy of https to git config --global --unset http.proxy # Unset the http.proxy

git config –global core.editor # To set your editor:

git config –global diff.tool vimdiff # Set vimdiff as the tool to edit diff

@end example

subsection Commit

@example git init # Initialize an empty repo git init –bare # Initialize a bare repo. It is useful for the dotfile projcet git status # Show the changed and unstaged files git add # Add(Stage) git reset # Remove from the stage git reset --hard # Remove all uncommitted changes git rm # Removes from both git and system git rm --cached # Removes from git git commit # Commit staged file, it opens an editor git commit -m "" # Commit with message git commit --amend # Edit previous commit message

git log # Show the comment log git log –oneline # Show the commit log in one line

git tag # List all tags git tag -a v1.0 -m “msg” # Create an annotated tag git show # Show the description of git tag --delete # Delete the tag

git rebase -i # Rebase commits from

@end example

Branch

@example git branch # List branches git branch -a # List local and remote branches git branch # Create branch git branch -d # Delete git branch -m # Rename the branch

git checkout # Checkout git checkout # Checkout (copy) the file in to this branch git merge # Merge to the current branch

git diff # Differences (unstaged files) between now and HEAD git diff -- # Differences between the same file in and git diff -cached # Differences between staged files and HEAD git difftool # Use difftool (e.g., vimdiff) to open and edit the file

git stash # Save uncommitted changes into stash git stash push -m “" # Stash changes with a message: git stash list # List all the stashed changes:

git stash pop # Pop changes from stagh @end example

Remote

@example git remote add # Add a remote reposiory named as git remote # Show remote git remote -v # Show more details about the remote git remote rm # Remove a remote repository git remote set-url # Change URL to for

git clone # Clone a remote repo to local

The following commands require git-remote-add

git push # Push this branch to the remote origin repo git push : # Push to the from the repo git fetch # Fetch remote to the branch git pull # Fetch and merge git pull <remotebranch: # Pull from to @end example

Submodule

@example git submodule update –init –recursive # Update all submodules:

git command for prompt in shell

git status –short | wc -l # Get the number of modified file in git git branch –show-current # Show the name of current branch git rev-list –count @@@{upstream@}..HEAD
# Count commits that local branch have but upstream does not @end example

SSH Over HTTP for GitHub

@example cat « EOF » ~/.ssh/config Host github.com Hostname ssh.github.com Port 443 User git EOF @end example