Git Cheatsheet

Add a file to your next commit

git add AMAAI

Add all file to your next commit

git add .

Descript your commit content

git commit -m 'description of this committed file'

List out and show which branch you are locating at

git branch

Create a new branch

git checkout -b [branch]

Switch to another branch

git checkout [branch]

Update local branch commits to GitHub

git push origin [branch_name]

Show modified files in working directory

git status

Show the different of what is changed but not committed

git diff [file]

Show the commit history for currently active branch

git log

Ignore folder or file when you process commit

Use nano which is a text editor to open .gitignore. All the folder and file inside .gitignore will be ignored and won’t be committed to GitHub.

nano .gitignore

Note

Any file begin with ‘.’ represent hidden file which is only shown in ‘ls -a’

Retrieve an repository from a hosted location via URL

git clone [url]

How to get URL for a repository?

Step 1: go to the repository page that you wanna clone. Download repository to your own GitHub account by clicking ‘fork’ button. git_clone_step1

Step 2: go to your repository page and click ‘Code’ button. git_clone_step2

For more Git commands, you can check via GitHub Education