Git
Git is a distributed version control system that tracks changes in any set of computer files
Basic commands
Start a new repository
git init <repository name>Add remote
git remote add <remote-name> <repo-link>Clone a repository
git clone <url>Stage all files
git add .Commit staged files
git commit -m "<commit-message>"Check the current status of files
git statusRemove recent changes, only in one file
git restore <filename>Remove all recent changes
git reset --hardClean all files and folders
git clean -dfFetch changes from remote
git fetch <remote> <branch>Cherry pick commits from any branch
git cherry-pick <commit-hash>Cherry pick range of commits
git cherry-pick <old-commit-hash>..<new-commit-hash>Check logs
git logCheck logs with commit hash
git reflogCheck diff of last commit
git diff HEAD^..HEADCheck logs - only last commit details
git log --name-status HEAD^..HEADRebase before merging to have a clean history
git rebase -i <branch-to-be-merged OR head-commit-hash>
git push --force-with-leaseMerge branch into current branch
git merge <branch>
OR
git merge <branch-to-be-merged> -m "merge message"
OR
git merge --ff-only <branch-to-be-merged>Push
Push commited changes
git push <remote-name> <branch-name>Force push
git push -f <remote> <branch>Force push (safer option)
git push <remote> <branch> --force-with-leaseFetch force pushed changes
git fetch; git reset --hard FETCH_HEADPush few commits only
git push <remote> <commit-hash>:refs/heads/<branch>Rebase
Start interactive rebase
git rebase -i <commit-hash>To advance interactive rebase
git rebase --continueTo abort interactive rebase
git rebase --abortType :x to execute interactive rebase
Use Pick to pick commits
Use Drop to drop commits
Use Edit to edit commits
LFS
Install/Uninstall LSF
git lfs install
git lfs uninstallTrack
git lfs track "*.<filetype>"
git lfs track --finename "<filename.filetype>"Fetch all
git lfs fetch --allPull LFS
git lfs pullPush LFS
git lfs push <remote> <branch> --allDelete
Delete local branch
git branch -d <branch-name>Delete remote branch
git push origin --delete <branch-name>Create
Create local branch
git checkout -b <new-branch-name> <source-branch>Amend
Amend last commit
git commit --amend