Git Commands
Git: A distributed version-control system. Keep the below diagram
in mind.
| Basic Commands: Usage Based |
| Empty Row PlaceHolder |
| Initializing a git repository |
git init git remote add origin remote_URL or git
clone remote_URL
|
| Empty Row PlaceHolder |
| Setting Configurations |
git config --global user.email "you@emailaddress.com" git
config --global user.name "Your Name"
|
| Empty Row PlaceHolder |
| Getting Information |
| Empty Row PlaceHolder |
| List All Local branches |
git branch |
| List All Remote branches |
git branch -r |
| List all Remotes(Origin etc) |
git remote -v |
| Show details of a particular Remote |
git remote show remote_name |
|
Check the state of the working directory and the staging
area
|
git status |
| Show all commits (tree) |
git log --graph --oneline |
| Check differences between all files |
git diff (Woking vs staged) git diff --staged (staged vs
last commit/local repo)
|
|
| Empty Row PlaceHolder |
|
Updating Local repository from Remote
|
git fetch git merge origin/branch_name or git pull
origin branch_name
|
| Empty Row PlaceHolder |
| Saving a Unit of work |
| Empty Row PlaceHolder |
| Stage files to be committed |
git add * or git add . or git add file1 file2 |
| Commit staged to your local repository |
git commit -m “commit message” |
| Shorthand for Staging and Committing |
git commit -am “commit message” |
| Send this commit to remote repository |
git push origin local_branch_name |
|
Pushing commits to remote repository when remote and local
branch names are different
|
git push origin local_branch_name:remote_branch_name
|
|
| Empty Row PlaceHolder |
| Advanced commands: **Beware |
| Empty Row PlaceHolder |
| Undoing/Reverting Changes |
| Empty Row PlaceHolder |
|
Fix last commit(Local Repo) **Never change a pushed commit
this way
|
git commit -m “xyz” git add missed_file git
commit --amend -m “added a missed file”
|
|
Undo Local History Commit/Stage but preserve file changes
in working directory
|
**git reset |
|
Undo Local History Commit/Stage and discard file changes
from working directory
|
**git reset --hard |
| Un-stage a staged file (reverse of git add) |
git restore --staged filename |
| Undo remote(pushed) commit |
**git revert <commit-Id/SHA> |
|
| Empty Row PlaceHolder |
Comments
Post a Comment