# 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
Generate keys with ssh-keygen
, the public key should be at ~/.ssh/id_rsa.pub
Upload an existing project to a remote repository, go inside your project's root folder and:
git init
git remote add origin <url>
git add <files>
git commit -m "<message>"
git push --set-upstream origin master
Start a new project from a remote repository just git clone <url> <new_folder>
Go into the <new_folder>
, do your thing, then git add <files>
, git commit -m "<message>"
and git push
.*
*.out
*.o
*.a
Depending on the project you could add to the list: main.c
, *.sh
, *.pdf
...
Check the Git Cheat Sheet from GitHub.
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 "<message>"
will add and commit ANY modified files that have already been added to the repository
git rm -rf <wrong_file/folder>
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 <file>
revert changes to match the current commit, could be the entire repo without <file>
git remote set-url origin <url>
changes an existing remote repository <url>
Completely messed up a local repo and want to start over?
Could try rm -rf .git
in the root repository folder
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 <file>
see the current changes, checks all files if you don't specify some
git diff-tree --no-commit-id --name-only -r <commit-hash>
list of files staged at a specific commit
git checkout <commit hash>
go to a specific commit (get the hash from the git log)
git checkout master
go to the latest commit