Git

GitGithubGitlab

SETUP

Configuring user information used across all local repositories

CommandPurpose
git config --global user.name "Name"Configure your user name
git config --global user.email "Email"Configure your user email
git config --listGit configurations information

Initilalizing

Initilalizing and Cloning repositories

CommandPurpose
git initInitilalizing a repository in an existing project
git clone [URL]Download and Initilalize repository from git hosting

Staging

CommandPurpose
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

CommandPurpose
git commitOpen 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

CommandPurpose
git diffChanges you did in all the unstaged files
git diff [file_name]Changes you did in changed file
git diff --stagedChanges you did in all the staged files

Branch & Merge

CommandPurpose
git branchList 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

CommandPurpose
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

CommandPurpose
git stashSave modified and staged changes
git stash listList all stashes
git stash applyApply the most recent stash
git stash apply stash@[id]Apply stash with given id
git stash dropDiscard the top from stash stack
git stash popApply the most recent stash

Sync & Update

CommandPurpose
git remote add [alias] [url]Adds a remote repository to your local repository
git fetch [alias]Fetch all the branches from remote repository
git pullFetch and merge from remote branch
git push [alias] [branch]Update the remote repository branch from local commits

Sync & Update

CommandPurpose
git statusStatus of the current repository
git logCommit history for current repository
git remote -vList all remote repositories