# BASH (~/.bashrc) ``` # Simple git prompt COLOR_GIT_CLEAN='\[\033[1;30m\]' COLOR_GIT_MODIFIED='\[\033[0;33m\]' COLOR_GIT_STAGED='\[\033[0;36m\]' COLOR_RESET='\[\033[0m\]' function git_prompt() { if git rev-parse --is-inside-work-tree > /dev/null 2>&1; then branch_name=$(git symbolic-ref -q HEAD) branch_name=${branch_name##refs/heads/} branch_name=${branch_name:-HEAD} echo -n " → " if [[ $(git status 2> /dev/null | tail -n1) = *"nothing to commit"* ]]; then echo -n "$COLOR_GIT_CLEAN$branch_name$COLOR_RESET" elif [[ $(git status 2> /dev/null | head -n5) = *"Changes to be committed"* ]]; then echo -n "$COLOR_GIT_STAGED$branch_name$COLOR_RESET" else echo -n "$COLOR_GIT_MODIFIED$branch_name*$COLOR_RESET" fi fi } function prompt() { PS1="\u@\h [\w$(git_prompt)] \$ " } PROMPT_COMMAND=prompt ``` # SSH (~/.ssh) Generate keys with `ssh-keygen`, the public key should be at `~/.ssh/id_rsa.pub` # GIT (~/src/repo/.git) Upload an existing project to a remote repository, go inside your project's root folder and: ``` git init git remote add origin git add git commit -m "" git push --set-upstream origin master ``` Start a new project from a remote repository just `git clone ` Go into the ``, do your thing, then `git add `, `git commit -m ""` and `git push` ## Git stuff: ### ~/src/repo/.gitignore ``` .* *.out *.o *.a ``` Depending on the project you could add to the list: `main.c`, `*.sh`, `*.pdf`... Check the [Git Cheat Sheet](https://education.github.com/git-cheat-sheet-education.pdf) from GitHub. ### Add stuff: `git add -f .gitignore` to force adding a file even if it's on the ignore rules `git add --all` add all files from all paths within your repository (follows ignore rules) `git add .` add all files from the current folder (also follows ignore rules) `git commit -a -m ""` will add and commit ANY modified files that have already been added to the repository ### Remove stuff: `git rm -rf ` careful, it's a single command to remove, stage, commit and push Completely revert lastest commit: ``` git reset --hard HEAD^ git push origin -f ``` `git checkout master -f ` revert changes to match the current commit, could be the entire repo without `` `git remote set-url origin ` changes an existing remote repository `` Completely messed up a local repo and want to start over? Could try `rm -rf .git` in the root repository folder ### Check stuff: `git status` pay attention to the messages `git log` check that your __HEAD__ is in the same commit as __origin/master__ `git ls-files` list of staged files (not necessarily pushed!) `git diff ` see the current changes, checks all files if you don't specify some `git diff-tree --no-commit-id --name-only -r ` list of files staged at a specific commit `git checkout ` go to a specific commit (get the hash from the git log) `git checkout master` go to the latest commit