Etc. Command
View Help
You can examine the functions of each command and option using the help command
# View all commands provided by Git
$ git help -all
# View all options available for a specific command
$ git [command] -help
Setup and Initialization
Initialize a Repository or clone an existing Repository
# Create a Git repository based on the current directory
$ git init
# Clone a remote Repository to a local Repository through URL
$ git clone [url]
Stage & Commit
You can commit using the stage area
# Check modified files in the current directory for the next commit
$ git status
# Add files for the next commit (stage)
$ git add [file]
# Unstage added files: changes are maintained
$ git reset [file]
# Show unstaged changes
$ git diff
# Show changes that are staged but not committed
$ git diff --staged
# Commit staged content with a message (create snapshot)
$ git commit -m "[descriptive message]"
Comparison and Inspection
You can inspect logs and changes
# Show all commit history of branchA that's not in branchB
$ git log branchB..branchA
# Display all commits containing changes to that file (also shows file name changes)
$ git log --follow [file]
# Show the change content (diff) of what's in branchA but not in branchB (compare states between branches)
$ git diff branchB...branchA
Share and Update
You can search for updates in a specific Repository and update the local Repository
# Add a specific remote Repository through url with an alias
$ git remote add [alias] [url]
# Fetch all branches and data from the remote Repository added with an alias to local
$ git fetch [alias]
# Merge the remote branch with the currently working branch to make it up to date
$ git merge [alias]/[branch]
# Send commits from the local branch to the remote branch
$ git push [alias] [branch]
# Fetch information from the remote Repository and automatically merge it into the local branch
$ git pull
History Modification
You can modify branches or commits or delete commit history
# Apply commits after a specific branch's fork to the currently working branch
$ git rebase [branch]
# Go back to before a specific commit and erase all staged changes
$ git reset --hard [commitish]
Temporary Storage
You can temporarily store modified or tracked files to switch branches
# Temporarily store modified or staged changes on the stack and remove them from current work history
$ git stash
# Show a list of changes temporarily stored on the stack
$ git stash list
# Apply changes temporarily stored on the stack back to the current work history
$ git stash apply
# Apply changes temporarily stored on the stack back to the current work history and delete from the stack
$ git stash pop
# Delete changes temporarily stored on the stack
$ git stash drop
Last updated