what | cmd | comments |
add all files | git add . | |
add only modified files and ignore untracked files | git add -u | |
remove a file | git remove <file> | also deletes from filesystem. If you wish to leave in file system use git rm –cached file.txt |
show changes | git status | use “git status -uno” to not show untracked files |
commit changes | git commit -m 'comment' | |
upload changes | git push origin master | use the -u flag on first push i.e. git push -u origin master. And it may be the case you only need “git push” after the first push? See http://stackoverflow.com/questions/6089294/why-do-i-need-to-do-set-upstream-all-the-time |
replace master branch with new brunch | git push -u -f origin master | the -f is the magic |
commit all changed files | git commit -a -m 'message' | you have to put the message in, apparently |
pull and overwrite untracked files | git fetch –all\\ git reset –hard origin/master | from here |
create new branch | git branch <name> | |
switch to branch | git checkout <name> | |
start a new branch with uncommitted changes | git checkout -b new_branch\\ git add . | use when you forget to start a new branch before editing code |
list names of remote branches | git branch -r | |
create local branch that tracks remote branch | git branch <localBranch> <remoteBranch> | |
reset local with remote head | git reset –hard origin/<branch> | |
merge branch (named test in this example) with master | git checkout master\\ git pull origin master\\ git merge test\\ git push origin master\\ | |
show changes of the last 2 commits. | git log -p -2 | |
Do this before you pull to show what commits you are about to retrieve, along with the names of the files.\\ | git fetch git log –name-status origin/master.. | |
add symbolic reference (alias) | git symbolic-ref refs/heads/stable refs/heads/v1.2.24 | in this example stable will point to v1.2.24 |
list all tags and show date of tag | git log –tags –simplify-by-decoration –pretty=“format:%ai %d” | |
Update the local list of remote branches | git remote update origin –prune | |
checkout remote branch and create new local branch w/ same name as remove | git checkout –track origin/<branch> | |
clone git into current (and non-empty) directory | git init .\\ git remote add origin <repository-url>\\ git pull origin master | from https://stackoverflow.com/questions/9864728/how-to-get-git-to-clone-into-current-directory |
- clone all remote branches as local branches:
git branch -a | grep -v HEAD | perl -ne 'chomp($_); s|^\*?\s*||; if (m|(.+)/(.+)| && not $d{$2}) {print qq(git branch --track $2 $1/$2\n)} else {$d{$_}=1}' | csh -xfs
(from https://stackoverflow.com/questions/67699/how-do-i-clone-all-remote-branches)