| Task | Command |
|---|---|
| Initial git setup | git config --global user.name {your name}git config --global user.email {your email}git config --global core.fileMode falsegit config --global push.default simpleecho .DS_Store >> ~/.gitignore_globalgit config --global core.excludesfile ~/.gitignore_global |
| ssh create key | ssh-keygen -t rsa |
| ssh list keys | ssh-add -l |
| ssh convert to .pem | openssl rsa -in ~/.ssh/id_rsa -outform pem > id_rsa.pemchmod 600 id_rsa.pem |
| ssh convert public to .pem | ssh-keygen -f ~/.ssh/id_rsa.pub -m 'PEM' -e > public.pemchmod 600 public.pem |
| add ssh key | ssh-add ~/.ssh/id_rsa |
| ssh remove keys | ssh-add -d ~/.ssh/id_notused_rsa |
| RSA fingerprint | ssh-keygen {-E md5} -lf id_rsa.pub |
| Task | Command |
|---|---|
| create repository | git init |
| add to repository | git add {file} |
| is it tracked? | git ls-files {file} |
| commit changes | git commit -a -m '{message}' |
| restore from old commit | git restore --source={commit} {file} |
| remove one change | git reset HEAD {file} |
| remove ALL changes | git reset --hard HEAD |
| remove after commit | git checkout -- {file} |
| revert | git revert --no-commit {hash}..HEAD (e.g., a1b2c3d4)git revert -continue -or- git revert --abort |
| remove/delete file(s) from repository | git rm --cached {file}`find . -name .DS_Store -print0 |
| add local to remote | 1. git remote add origin[email protected]:unrivaledmhall/{project}.git2. git push --set-upstream origin master3. git push -u origin --all4. git push origin --tags |
| change origin (rename) | git remote set-url origin {url} |
| really clone repository | mkdir repocd repogit clone --bare {path/to/repo.git} .gitgit config --unset core.bare -or- git config --bool core.bare falsegit reset --hard |
| shallow clone | git clone --depth 1 {repo}.git |
| shallow to full clone | git fetch --unshallow |
| ignore filemode | git config {--global} core.fileMode false |
| refresh submodules | git submodule update --init –recursive -or- git clone --recursive git://repo.git |
| Task | Command |
|---|---|
| add a branch | git checkout -b {branch}-or- git branch {branch}git checkout {branch}-then- git push --set-upstream origin {branch} |
| change active branch | Same as above (if creating a branch) -or- git checkout {file} |
| list branches | git branchgit ls-remote --heads {remote-name} |
| list tracked files | git ls-tree -r HEAD --name-only |
| show changes | git status -uno |
| view log (history) | git log --oneline --decorate |
| merge with master (aka "fast forward") |
git checkout mastergit merge {branch} |
| delete branch | git branch -d {branch}git push origin --delete {branch} |
| rename git branch | git checkout {old name}git branch -m {new name}git push |
| Task | Command |
|---|---|
| add tag | git tag -a {tag} [commit number] -m '{tag annotation}' |
| remove tag | git tag --delete {tag}git push --delete origin {tag} |
| push tag | git push origin {tag} |
| remove tag | git tag -d {tag} |
| add tag, remote | git push origin {tag} |
| remove tag, remote | git push origin --delete {tag} |
| Task | Command |
|---|---|
| "stash" working state | git stash |
| "un-stash" working state + remove | git stash pop |
| show stashes | git stash list |
| "un-stash" working state | git stash apply {stash} --index (e.g., stash@{2}) |
| remove a stashed state | git stash drop stash@{0} |