Skip to content
bobby_dreamer

Git Theory - 7 - Git Everyday

notes, git1 min read

This picture, sort of gives an overview of some major git commands and where it fits in the Git World

git flowchart

Below are some useful git commands, tests and references.

Git Configuration
DescriptionGit 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 commitsgit config --global user.email bobby.dreamer@gmail.com
Git Everyday
DescriptionGit Command
Staging filesgit add .
Commitgit commit -m "Added/Updated/Deleted November 2020 : route-name, page-name : Did what ?
Commit added and changedgit commit -am "Added/Updated/Deleted November 2020 : route-name, page-name : Did what ?
List statusgit status
Check ignoregit check-ignore -v *
Creating tagsgit tag 1.0.0 <commitID>
Replaces file in working directorygit checkout -- fileA.txt
Git Branch
DescriptionGit Command
List all the branches in your repo, and also tell you what branch you're currently ingit branch
Switch from one branch to anothergit checkout branch_name
Create a new branch and switch to itgit checkout -b branch_name
Deletign a branchgit branch -d <branchname>
Forcibly delete the branch(before merging)git branch –D feature
Git Remote
DescriptionGit Command
Clone a repository into a new directorygit clone repo_url
Download objects and refs from remote repository for master branchgit fetch origin master
Download objects and refs from remote repository for all branchesgit fetch --all
List all currently configured remote repository urlsgit remote -v
Push and add upstream(tracking) reference for argument-less pullgit push -u origin master
Pull from remote master and set as upstreamgit pull -u origin master
Fetch and merge changes on the remote server to your working directory:git pull
Pushing commits to remotegit push
Send changes of master branch to remote origin master branchgit push origin master
Delete remote branchgit push origin -d feature
Push all branches to your remote repositorygit push --all origin
Push all tags to remote repositorygit push --tags origin
Other Git commands
DescriptionGit Command
Search the working directory for foo()git grep "foo()"
List of all files in a commit treegit ls-tree --name-only -r HEAD
List of all files changed in a commitgit diff-tree --no-commit-id --name-only -r HEAD

# References

Cheatsheet

Visualizations

Rebasing

Git flow

Git advance topics

Materials

# 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