1. Setup Git and GitHub Global Configuration
git config --global user.email "gautamthakur1983@gmail.com"git config --global user.name "Gautam Thakur"git config --global listgit config --list2. Git Lifecycle | Initilize, Status, Add, Commit
git statusgit initgit addgit commit -m "Commit Message"git loggit log --oneline3. Git Difference between last commit changes and current version changes
git diff4. Git Compare between 2 different Git Commits
git diff eac4c5b 82485b15. Git Statsh - To save some changes for temporary purpose ## Pop take out stash and clear but apply take out stash but not clear
git stash(To save current changes for temporary)git stash pop(To take out all stash contents)git stash listgit stash clear(To clear all the stash changes)git stash save "NAME" git stash save "NAME1"git stash sapply 0 or 1(0 for name, 1 for about) after that run git stash cleargit stash clear6. Git Restore - It help us to restore previous state/commit or remove the changes we did
git restore FILENAME(Restore all the changes in the working directory) It work for the individual file.git restore --staged FILENAME(Restore all changes from staging area)
7. Git Branch - Creating, Deletion, Merging etc.
List all the branches
git branchgit branch <NEW_BRANCH_NAME>git checkout <BRANCH_YOU_WANT_TO_USE>git merge <UPDATED_BRANCH>git branch -d <BRANCH_YOU_WANT_TO_DELETE>Delete the feature branch remotely on GitHub
git push origin --delete <BRANCH_YOU_WANT_TO_DELETE>
8. Git Pull - Pull all the changes from the remote repository
To pull the changes from remote repositorygit push origin maingit config pull.ff falseNote: In Case of Merge Error While Pulling: [Click Here](https://stackoverflow.com/questions/62653114/how-can-i-deal-with-this-git-warning-pulling-without-specifying-how-to-reconci)
9. Git Merge Conflict
Accept Current Changes | Incoming Change | Both the changes
10. Git Express commit
(Only work if file is already staged once. It will not work for new file inside working area)
git commit -a -m "COMMIT MESSAGE"orgit commit -am "COMMIT MESSAGE"11. Git - Create new branch and checkout at the same time
git checkout -b <NEW_BRANCH_NAME>12. Git - Check all latest commit in all the branches
git branch -v13. Git Information about all the remote branches
git branch -r14. Git - Check all the connected Remote Repository
git branch -v15. Git - To check all the Merged and not Merged branches
git branch --mergedgit branch --no-merged
16. Git - Delete the branch which is not merged with main
git branch -D <BRANCH_NAME)17. Git - Rebase | Rebase and Merge are use to integrate changes.
git rebase featuregit rebase main18. Git Rebase vs Git Merge
- Merge - Git merge keep history of everything. Have idea about conflicts##
- Rebase - Order of change not preserve in git rebase. No idea about merge conflict. After Rebase all the changes always added at the top. In spite of other commits in between. After Rebase, history on commit will be same with other branch.
19. .gitignore
.gitignore file is to ignore files from the current code which you did not want git to track. Like environment variable, password, any critical data and unwanted files and folders..env
/directory
20. Git Squash - Merge multiple commit into one single commit
git rebase -i HEAD~921. Git Revert - To Revert changes of any commit, all the change of that commit will be removed
git revert 151304022. Git Reset - Soft, Mixed and Hard
Soft Reset
git reset --soft HEAD~Soft Reset will remove your Git commit and add your latest chnage to the staging area with loosing any data.
Mixed Reset
git resetHard Reset
git reset --hard HEAD~23. Git Tag - Better for history
For create a git tag
git tag v0.1Push tag to remote repository
git push origin v0.1git tag list will show all the tags
git tags list | git tag --listNote: We can RELEASE with tag what all the changes has been done as compare to previous tag.
git tag with name and commit message
git tag with name and commit message
git tag -a [tag_name] [commit_SHA] -m "commit message"git checkout v0.1Note: Do it new brach if you checkout previous tag or commit and your start commit from that commit then it will create a new timeline and thungs will messay for you so back to the latest commit in the branch run the command.
In case of Branch detach
Jump to previous any commit (for testing)
git checkout maingit checkout [commit_SHA] Delete a git tag
git tag -d [tag_name]git push origin --delete [tag_name]24. Git Clone - Clone a GitHub Repository
git clone https://github.com/Gautam29683/git-github-mastery.gitLet's assume we have clone the code from someoneelse Repository and want to use with own repository
git remote rm upstream25. GitHub README Profile and Project Useful Resource:
- https://emojipedia.org/ - For Emogies
- https://simpleicons.org/ - For Icons Packs
- https://shields.io/. - For Badges
- https://readme.so/. - For Project README
