This picture, sort of gives an overview of some major git commands and where it fits in the Git World
Below are some useful git commands, tests and references.
Git Configuration
Description | Git Command |
---|---|
Configure the author name to be used with your commits. | git config --global user.name "Sushanth Bobby" |
Configure the author email address to be used with your commits | git config --global user.email bobby.dreamer@gmail.com |
Git Everyday
Description | Git Command |
---|---|
Staging files | git add . |
Commit | git commit -m "Added/Updated/Deleted November 2020 : route-name, page-name : Did what ? |
Commit added and changed | git commit -am "Added/Updated/Deleted November 2020 : route-name, page-name : Did what ? |
List status | git status |
Check ignore | git check-ignore -v * |
Creating tags | git tag 1.0.0 <commitID> |
Replaces file in working directory | git checkout -- fileA.txt |
Git Branch
Description | Git Command |
---|---|
List all the branches in your repo, and also tell you what branch you’re currently in | git branch |
Switch from one branch to another | git checkout branch_name |
Create a new branch and switch to it | git checkout -b branch_name |
Deletign a branch | git branch -d <branchname> |
Forcibly delete the branch(before merging) | git branch –D feature |
Git Remote
Description | Git Command |
---|---|
Clone a repository into a new directory | git clone repo_url |
Download objects and refs from remote repository for master branch | git fetch origin master |
Download objects and refs from remote repository for all branches | git fetch --all |
List all currently configured remote repository urls | git remote -v |
Push and add upstream(tracking) reference for argument-less pull | git push -u origin master |
Pull from remote master and set as upstream | git pull -u origin master |
Fetch and merge changes on the remote server to your working directory: | git pull |
Pushing commits to remote | git push |
Send changes of master branch to remote origin master branch | git push origin master |
Delete remote branch | git push origin -d feature |
Push all branches to your remote repository | git push --all origin |
Push all tags to remote repository | git push --tags origin |
Other Git commands
Description | Git Command |
---|---|
Search the working directory for foo() | git grep "foo()" |
List of all files in a commit tree | git ls-tree —name-only -r HEAD |
List of all files changed in a commit | git diff-tree —no-commit-id —name-only -r HEAD |
# References
Cheatsheet
Visualizations
- Bit-Booster - Offline Commit Graph Drawing Tool
- CS Visualized: Useful Git Commands
- A Visual Git Reference
Rebasing
- Rebase workflow : Randy Fay
- Rebase workflow : Catherine Chepkurui
- Rebase example: YT : Order of commit is changed.
Git flow
Git advance topics
- Git Extras
- BFG Repo-Cleaner : Removes large blobs
- Rewriting Your Git History and JS Source for Fun and Profit
Materials
- Powerpoint Slides which i had prepared in Dec 2018.
# Git Theory
- Origin : How it all began. What is git ? and Terminologies used in this series.
- Basics : config, init, add, rm, .gitignore, commit, log, blame, diff, tag, describe, show and stash
- Undos : checkout, reset, revert and restore
- Branching : Git Branching
- Internals : Git Internals
- Collaboration : Git remote repository
- Local Git Hooks : Sample on pre-commit and prepare-commit-msg hooks