Git
Install¶
Install git using homebrew with the following command:
Configuration¶
Set username¶
Set email¶
Set credential helper¶
This will store your credentials in a plain text file at ~/.git-credentials
.
Usage¶
Init¶
Initialize got tracking inside current directory
Initialize git tracking inside a new directory
Clone¶
Clone a repository
Clone only a specific branch
Clone a repository to a specific directory
Branch¶
Create a new branch
Create a new branch and switch to it
Switch to a branch
Delete a branch
Delete a branch forcefully
Merge a branch
Merge a branch with a message
Add¶
Add a file to staging area
Add all files to staging area
Stage all files except a specific file
git add -u
git git reset HEAD main/dontcheckmein.txt #or
git restore --staged main/dontcheckmein.txt
Remove a file from staging area
Commit¶
See the changes in the staging area
Saving the staged changes with a message
Saving the staged changes with a message and adding all changes
Edit the last commit message
Saving¶
Saving stage and unstaged changes
Saving stage and unstaged changes with a message
Saving stage and unstaged changes with a message and include untracked files
Apply the last stash
Apply a specific stash
Apply the last stash and remove it from the list
Remove the last stash
Remove a specific stash
Diff¶
See the changes between the working directory and the staging area
See the changes between 2 commits
Push to a previous commit¶
There are 2 ways of doing this
Reset¶
Use with caution
Use this wisely as this would manipulate the git history and could very well jeopardise everything for you.
--soft
- Moves the HEAD to the commitId and keeps the changes in the staging area--mixed
- Moves the HEAD to the commitId and keeps the changes in the working directory--hard
- Moves the HEAD to the commitId and discards all changes--merge
- Moves the HEAD to the commitId and keeps the changes in the staging area and working directory--keep
- Moves the HEAD to the commitId and keeps the changes in the working directory
Read more
Revert¶
GitHub via SSH¶
Add SSH key to your GitHub account