Git - Useful Commands Cheatsheet

Tags : versioning git

Setup Useful commands
# SETUP
$ git config --global user.name "Your Name"
$ git config --global user.email your@email.com

$ git init

# SSH
$ ssh-keygen -t rsa -b 4096 -C "your@email.com"
Copy
$ cat < ~/.ssh/id_rsa.pub

# CLONE
$ git clone https://github.com/user/my_project.git
Remote
# ADD
$ git remote add origin git@github.com:company/my_project.git

# MODIFY
$ git remote set-url origin git@github.com:company/my_project.git

# VIEW REMOTES
$ git remote -v
Git Flow Example
CREATE A BRANCH
$ git branch my_feature && git checkout my_feature
or in one command
$ git checkout -b my_feature

SUBMIT A CHANGE
$ git add readme.md
$ git commit -m "Added readme file"
$ git push origin my_feature
Logging
$ git log

LOG WITH GRAPH
git log --graph --full-history --all --pretty=format:"%h%x09%d%x20%s"

LOG REPOSITORY
Review complete modifications history
$ git reflog

WHO
$ git blame master -- readme.md
with lines
$ git blame -L 40,60 readme.md
$ git blame -L 40,+21 readme.md
Remove ignored folder
$ git rm --cached -r #_FOLDER_NAME_#