command |
Description |
| git init | initialize git repository |
| git add . | add all changed file to staging are |
| git commit -m "my message" | commit all changes to the local repository |
| git pull | pull latest changes from repository |
| git push | push all changes to remote repository |
| git config --global user.name "YOUR NAME" | setup user name |
| git config --global user.email "YOUR EMAIL ADDRESS" | setup email |
| git status | see changed file |
| git diff | see changed file in details |
| git stash save "my message" | save my changes to the stash |
| git stash pop | get the last stash and add it to the current branch |
| git stash pop stash_name | get specific stash and add it to the current branch |
| git checkout -- file_name | get file_name file from last commited checkout |
| git reset HEAD file_name | un stage file_name from staging area |
| git branch | list of my branch (current branch will be marked *branch_name) |
| git branch branch_name | create a branch with name branch_name |
| git checkout branch_name | switch to the branch_name from current branch |
| git branch -d branch_name | safe delete current branch( make sure to switch to a different branch before deleting a branch) if use -D then it will be force deletion of a branch |
| git merge branch_name | merge branch_name branch to the current branch |
| git diff branch_name1...branch_name2 | difference between two branch |
| git checkout 234234rwerwe | git checkout to specific position (last string is sha value which we can get by git log --oneline) it will put my changes to the staging area right before making any commit |
| git diff --staged | current diff in the staged area |
| git revert sha_value | revert to the position before making changes |
| git reset --soft sha_value | (make sure u do git log and copy latest sha_values in case you want to go to recent value)
make the sha_value position as current head all commits after sha_value is gone but all changes will available in staging area |
| git reset --mixed sha_value | (make sure u do git log and copy latest sha_values in case you want to go to recent value)
make the sha_value position as current head all commits after sha_value is gone but all changes will available in working directory means modified position of the file we ware working on just before git add |
| create .gitignore file at root | for ignoring file in git tracking
e.g.
|
| git rm --cached filename | stop tracking filename from now one (file will be in our working directory but wont be tracked |
| git log --grep="temp" | show log any commit that has temp keyword in it |
| git log --since = 2.days | show log anything within two days |
| git log --author="sazzad" | show log all commit done by sazzad |
| git push -u origin feature_branch_name | push my branch to remote repo |
| git checkout -b feature_branch_name origin/feature_branch_name | if you want to work on that branch, you'll need to create a local tracking branch |
| git log --pretty=format:"%h%x09%an%x09%ad%x09%s" | Minified log |
| git log --graph --oneline --decorate --all | pretty way look at log |
| git branch --merged | this will show list of branches that are included in the current branch. if this shows 3 branches it means
I wont loose any data if i delete one of the branches in the list |
| git branch -m old_branch_name new_branch_name | rename branch name |
| git merge --no--ff branch_name | marge branch with a new commit even thought fast forward merge is available. we should do this if we want
to keep track of our merges |
| git log branch_name --oneline -3 | print log of specific branch max 3 (-3 optional) |
| git merge --abort | abort merging |
| git commit | only use after fixing merge conflicts ( no commit message needed here ) |