Dictionary
Pre-Git Stuffs
- Make a new folder (aka directory)
mkdir <FOLDERNAME>
- Navigate into an existing folder (aka change directory)
cd <FOLDERNAME>
- List the items in a folder
ls
Configuration
- Check Git version
git --version
- Set your name
git config --global user.name "Your Name"
- Set your email
git config --global user.email youremail@example.com
- Set your Github account
git config --global user.username "USERNAME"
Git Basics
- Turn Git on for a folder
git init
- Check status of changes to a repository
git status
- View changes to files
git diff
- Add a file's changes to be committed
git add <FILENAME>
- To add all files changes
git add .
- To commit (aka save) the changes you've added with a short message describing the changes
git commit -m 'your commit message'
- Copy a repository to your computer
git clone <URL>
Branch
- Create a new branch:
git branch <BRANCHNAME>
- Move onto a branch:
git checkout <BRANCHNAME>
- You can create and switch to a branch in one line:
git checkout -b <BRANCHNAME>
- List the branches:
git branch
- Rename a branch you're currently on:
git branch -m <NEWBRANCHNAME>
Remote
- Add remote connections
git remote add <REMOTENAME> <URL>
- Set a URL to a remote
git remote set-url <REMOTENAME>
- View remote connections
git remote -v
Pull
- Pull in changes
git pull <REMOTENAME> <BRANCHNAME>
- Pull in changes from a remote branch
git pull
- See changes to the remote before you pull in
git fetch --dry-run
Push & Merge
- Push changes
git push <REMOTENAME>
- Merge a branch into current branch
git merge <BRANCHNAME>
Deletion
- Delete a local branch
git branch -D <BRANCHNAME>
- Delete a remote branch
git push <REMOTENAME> --delete <BRANCHNAME>