Git commands

###############################
#### staging area related #####
###############################

#add a file to staging area
git add . #add all files to staging area
git add <filename>

#un-stage a file
git reset HEAD <filename> 

#discard the change of a file, get original file from HEAD
git checkout -- <filename> #-- mean current branch
git checkout HEAD <filename> #same

#####################################
#### checking status and history ####
#####################################
git log -5 (show the last 5 commits)
git log --oneline
git log --since="2016-04-20"
git log --since=2.weeks
git log --graph --oneline --decorate -all -10

git status #see what is in staging area

git diff #working directory
git diff --cached #staging area
git diff --staged #staging area
git diff <filename> 
git diff master..new_branch
git diff <commit> <filename>
git diff <commit_a>..<commit_b> <filename>
git diff HEAD^ 
git diff HEAD~2

#########################
#### file management ####
#########################
.gitignore #files that git will not track
git rm --cached <filename> #remove from tracking


##################
#### branches ####
##################

git branch <new_branch>
git checkout <new_branch>
git branch <new_branch> <commit> #open new branch based on a commit
git checkout -b new_branch #one step, create and change
git diff master..new_branch
git branch -m new_branch new_name_branch #rename a branch
git branch -d branch_to_delete #will warn if the branch is not merged yet
git branch -D branch_to_detete #without warning, force delete

git checkout master 
git merge new_feature #merge the new feature branch into master

#######################
#### collaboration ####
#######################
git remote add origin https://github.com/user/repo.git
git remote -v #show all the remote

git fetch #get update from remote
git merge origin/master #merge in the changes

git pull #perform git fetch and then git merge into current branch

git branch -r #show remote branches
git branch -a #show all branches
git push or git push origin master#push your update to remote
git push --set-upstream origin new_branch_name #push a new branch to remote

results matching ""

    No results matching ""