A quick guide to use Git without leaving your terminal.
-
Add your username:
$ git config --global user.name "<username>" -
Add your email:
$ git config --global user.email "<email>" -
Check if everything is alright:
$ git config --list
This may seem trivial, but actually it's really important. If your credentials are not properly set, your commits will not appear as yours.
-
If you want to clean your username and email just type:
$ git config --global --unset-all user.name && git config --global --unset-all user.email
-
Create a new repository:
$ git init
-
Clone a repository:
$ git clone <repository>
Clone a repository directly into the current directory (if empty):
$ git clone <repository> .
-
Check for changes:
$ git status
-
Stage all changes to be committed:
$ git add -A
-
Commit your changes:
$ git commit -m <message>
-
List all branches:
$ git branch
-
Create a branch:
$ git branch <branch-name>
-
Switch to another branch:
$ git checkout <branch-name>
Create a branch and automatically switch to it:
$ git checkout -b <branch-name>
-
Delete a branch:
$ git branch -d <branch-name>
-
Add a remote:
$ git remote add <remote-name> <repository>
-
Pull changes from remote repository:
$ git pull <remote-name> <branch-name>
-
Stash changes:
$ git stash
Stash changes and with a description:
$ git stash save <optional-message>
Stash changes including untracked files and with a description:
$ git stash save -u <optional-message>
-
List stash entries:
$ git stash list
-
Apply saved changes from the latest stash entry:
$ git stash pop
Apply saved changes from the indicated stash entry:
$ git stash pop 'stash@{n}' -
Remove all stash entries:
$ git stash clear
-
Squash commits with (interactive) rebase:
$ git rebase -i <branch>
In case of conflict, solve them and then continue with the rebase:
$ git rebase --continue
-
Abort rebase:
$ git rebase --abort
-
Rename a file to the same name but with a different case:
$ git mv FILE FILE.tmp && git mv FILE.tmp file
Do whatever you want with this, it’s public domain.