Cheatsheet for git
This will be the reference doc for some of most common git command used for software development.
Create Git Repositories
- git init – used to initialize new repositories
- git clone url – Used to clone existing git repositories from URL
Observe Changes
- git status – Used to check the current changes in working directory
- git diff filename – Used to get the difference/changes between files
Logging
- git log – Used to get details logs for current branch
- git log –oneline – used to get compact log in oneline for each commit
Adding Commit
- git add filename/directory name – used to add file/directory to satging area, so that it can be commited.
- git commit -m “message” – used to push the commit to local repositories from staging area
Push/Pull Changes
- git push – used to push you local commit to remote repositories
- git pull – used to pull changes from remote repositories to local repositories and merge if any changes available
- git fetch – used to fetch the changes from remote repositories to local repositories(but do not merge it like git pull)
Change Integration
- git merge – used to merge two branches and keeping all the commits(by default)
- git merge –squash – used to merge two branch and only creates the single commit message and ignores other commit message.
- git rebase – used go rebase the source branch(current branch) and merge changes if available any.
Branches
- git branch – list all available branches
- git branch new_branch– used to create new branch from current branch
- git branch -d/-D branch_name – used to delete branch from local repositories
- git checkout branch_name – used to switch between branches.
- git checkout -b new_branch – used to create branch and checkout to newly created branch
When mistakes are made
- git revert – Used to revert any changes pushed to remote repositories by created a new revert commit(Recommended when reverting any changes to public branch/repositories).
- git reset – Used to reset or delete the commit pushed to the remote repositories.
Thanks for reading…