Popular git commands used every day.

$ git init
$ git config --global user.email "PUT_YOUR_EMAIL_HERE" 
$ git config --global user.name "PUT_YOUR_NAME_HERE"
$ git status
# To add all the files not staged: 
$ git add .
# To stage a specific file:
$ git add index.js
# To stage an entire directory:
$ git add images
# Adding a commit with a message 
$ git commit -m "PUT_YOUR_COMMIT_MESSAGE_HERE"
# Create a new branch 
$ git branch <branch_name>
# List all remote or local branches
$ git branch -a
# Delete a branch
$ git branch -d <branch_name>
# Switch to another branch 
$ git branch <branch_name>
# Create a new branch and also switches to it.
$ git branch -b <branch_name>
$ git merge <branch_name_you_want_to_merge>
$ git remote add <remote_name> <remote_server_url>
# Example: git push origin master 
$ git push <remote_alias_name> <branch_name>
# Push all local branches to the remote repository
$ git push --all <remote_alias_name>
# To delete a branch from remote repository.
$ git push <remote_alias_name> :<branch_name>
# Example: git pull origin master 
$ git pull <remote_alias_name/remote_url>
# Show entire git log 
$ git log
# Show git log with date pameters
$ git log --<after/before/since/until>=<date>
# Show git log based on commit author
$ git log --<author>="Author Name"
# Unstages the file but preserves the file contents 
$ git reset <file>
# Undoes all the commits after the specified commit and preserves the changes locally
$ git reset <commit>
# Discards all histories and goes back to the specified commit
$ git reset --hard <commit>
$ git clone <remote_URL>
# To remove a file from the working index (cached): 
$ git rm --cached <file_name>
# To delete a file (force):
$ git rm -f <file_name>
# To remove an entire directory from the working index (cached):
$ git rm -r --cached <directory_name>
# To delete an entire directory (force):
$ git rm -r -f <file_name>
# To save modified files temporarily: 
$ git stash save
# To restores the most recently stashed files:
$ git stash pop
# To lists all stashed changesets:
$ git stash list
# To discards the most recently stashed changeset:
$ git stash drop
$ git show <commits/tags>
# To print out the differences between the working directory and the latest commit: 
$ git diff
# To compare two commits:
$ git diff <first_commit_hash> <second_commit_hash>
# To compare two branches:
$ git diff <first_branch> <second_branch>
# To compare specific file across branches:
$ git diff <first_branch> <second_branch> <file_path>
$ git tag <commit_ID>

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
CodingHub

CodingHub

Coding Hub — Learn & Build Your Career