SETUP
Configuring user information used across all local repositories
Command | Purpose |
---|
git config --global user.name "Name" | Configure your user name |
git config --global user.email "Email" | Configure your user email |
git config --list | Git configurations information |
Initilalizing
Initilalizing and Cloning repositories
Command | Purpose |
---|
git init | Initilalizing a repository in an existing project |
git clone [URL] | Download and Initilalize repository from git hosting |
Staging
Command | Purpose |
---|
git reset [file_name] | Add file with given file_name in your project to the staging area |
git add . | Add all files in your project to the staging area |
git add gan* | Add all files starting with gan in your project to the staging area |
git reset [file_name] | Discarding file from staging area |
Commit Changes
Command | Purpose |
---|
git commit | Open a editor where you can add a commit message |
git commit -m "message" | Add a commit message without opening the editor |
git commit -a -m "message" | Add and commit tracked files (skip staging area) |
git commit -am "message" | Add and commit tracked files (skip staging area) |
Diff
Command | Purpose |
---|
git diff | Changes you did in all the unstaged files |
git diff [file_name] | Changes you did in changed file |
git diff --staged | Changes you did in all the staged files |
Branch & Merge
Command | Purpose |
---|
git branch | List all the branches(Current branch marked with *) |
git branch {branch_name} | Creates a new branch |
git checkout {branch_name} | Switch to another branch or newly created branch |
git checkout -b {branch_name} | Create and Switch branch |
git branch -d {branch_name} | Delete a branch. Only use this only if branch is merged |
git merge {branch_name} | Merge the branch's history into current branch |
Files
Command | Purpose |
---|
git rm [file_name] | Remove the file and stage the removal |
git mv [old_file] [new_file] | Rename or Move files and stage the move |
Temporary Commits
Command | Purpose |
---|
git stash | Save modified and staged changes |
git stash list | List all stashes |
git stash apply | Apply the most recent stash |
git stash apply stash@[id] | Apply stash with given id |
git stash drop | Discard the top from stash stack |
git stash pop | Apply the most recent stash |
Sync & Update
Command | Purpose |
---|
git remote add [alias] [url] | Adds a remote repository to your local repository |
git fetch [alias] | Fetch all the branches from remote repository |
git pull | Fetch and merge from remote branch |
git push [alias] [branch] | Update the remote repository branch from local commits |
Sync & Update
Command | Purpose |
---|
git status | Status of the current repository |
git log | Commit history for current repository |
git remote -v | List all remote repositories |