get existing branch from remote
git checkout -b <branch> origin/<branch>
replace current commit with the files currently in the directory
git commit --amend -C HEAD
change commit message
git commit --amend
take all changes to tracked files and make a commit
git commit -all
what chnages are going to be committed
git diff --cached
changes files in the working tree and the last commit
git diff head
cleaning git -d directory , -x - untracked and ignored, -f forced (-n only shows files)
git clean -dxf
git log --oneline
update all remotes
git fetch -all
reset merge to return to the stae before merging
git reset --merge
remove untracked changes in the working directory
git stash --keep-index
bring back the stashed changes to the working tree
git stash pop
difference between local master and origin/master (or any other branch)
git diff master origin/master
git diff master file (on branch)
git log
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
git list branches (-a all local and remote, -r only remote branches)
git branch -a
git branch -r
git show files in directories
git st -u
git rebase on master local
git rebase origin/master
push new branch
git push -u origin your_branch
git stash - store uncommited changes (clean local repo)
git stash
git stash list
git stash apply (last stash otherwise explicitly cite which one)
git stash drop - drop last one
git stash clear - remove ALL
git stash apply SHA1 - in case you dropped the stash
git push branch
git push origin branch_name
git diff modified and last commit
git diff HEAD file
after rebase , push
git push origin your_branch --force
keeps history visible on graph
git merge --no-ff
remove last commit
git reset --hard HEAD~1
or use soft if you want to keep changes
git track remote branch (create new one)
git checkout --track origin/daves_branch
git move files
git mv FILE destination
git rebase before pushing (only commits which differ from upstream - master)
git rebase -i @{u}
fix conflicts during merge
git mergetool
commit deleted files
git add -u
git any commit diff (example diff last commit with previous)
git difftool HEAD HEAD~1
git diff label
git diff tag1 tag2 -- some/file/name
last commit change
git commit --amend
git rename (folder,files)
git mv old new
git diff file wiht previous
git diff HEAD~2 main.c
show tags (label)
git tag
git annotated tag (not lighweight!)
git tag -a v1.4 -m 'my version 1.4'
git diff staged
git diff --cached file
squash merge
git checkout master
git merge --squash newstuff
show untracked files
git ls-files --other --exclude-standard
only files name which differs
git diff --name-only master <branch>
brach remove from remote
git push origin :newfeature
delete branch
git brach -d branch_name
show branch with commits
git show-branch
show which branch was merged (be concious about squash/rebase)
git branch -r --merged master | sed 's/ *origin\\///' | grep -v 'master$'
get tag
git fetch -t
push tag
git push origin [tagname]
git github forked update (new upstream, then merge to master fork) - mbed as an example
git remote add --track master upstream git://github.com/mbedmicro/mbed.git
git merge upstream/master
git (github) update fork
git fetch upstream
git merge upstream/master
revert bad rebase
git reflog (this displays history, check which one you want to return to)
git reset <sha> --hard
show commit with sha (example 1e8e50996)
git show s1e8e50996
fetch a branch github (already forked)
git remote add theirusername git@github.com:theirusername/reponame.git
git fetch theirusername
git checkout -b mynamefortheirbranch theirusername/theirbranch
set tracking branch (current branch to track upstream/foo)
git branch -u upstream/foo