Skip to content

Instantly share code, notes, and snippets.

@MSHADroo
Last active February 3, 2019 21:23
Show Gist options
  • Save MSHADroo/580cd78ae02cb39640b898c11d4dd3d7 to your computer and use it in GitHub Desktop.
Save MSHADroo/580cd78ae02cb39640b898c11d4dd3d7 to your computer and use it in GitHub Desktop.
Git Commands

git init //git init
git status //show the status of git directory
git add . //add all file of direcotry to stage
git commit -m "message" //commit the statge
git commit -a -m "message" //add modified files to stage and commit
git rm --cached filename //remove file from stage
git diff //show diff of commited state with modified file
git diff --help //show diff help
git log //show all commit informations
git log --help //help for git log
git log --oneline //show commites in one line format
git log -2 --online //show 2 last commit in one line format
git log -p //show changes in every commit
git log --stat //show ststs of all commits
git checkout -- filename //revert file to last commit
git reset HEAD filename //unstage modified file
git reset commitID //set the last commit to this id , and all changes after this commit will be on commited
git reset --hard commitID //revert to commit id and all code revert to this commit and all new file after that commit will be deleted
git branch --help
git branch dev //make new branch as dev
git branch -a //show list of all branch
git checkout dev //switch to dev branch
git checkout -b dev //make new branch as dev and switch to dev branch
!importan before each switch betweeb branch you must commit all uncommited changes , if you dont commit every changes will be moved to other branch git merge develop //merge the new branch to source or master branch, first you must be in master and then use this command
git log --graph //show log and branches in graph
!importan on merge conflict first see git status to find problem file and then fix file manualy and then add and commit it
git stash or git stash save "message" //temporary save changes in branch to temp position
git stash --help
git stash list //show list of all saved stash
git stash drop //delete specific stash
git stash show //show info about saved stash
git stash apply //copy chnages in stash to branch and remain stash
git stash pop //copy chnages in stash to branch and drop stash
git config --global user.name "Mohsen Shadroo" // set name globaly , if use globaly config will be placed in userDirctory/.gitconfig file
git config --global user.email "mshadroo[at]gmail.com" //set email globaly , if dosent use globaly config will be placed in .git/config file
.gitignore //file for exclude some file and folder from commit
git rm --cached -r . //to untrack a file add it to gitignore and then use this command and then "git add . " and commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment