- HEAD is a reference to the last commit in the currently checked-out branch.
- For more info: https://stackoverflow.com/questions/2529971/what-is-the-head-in-git
git log origin/master..HEAD
git diff origin/master..HEAD
git clean -fdX
- git remote add remote-name repository-URL
- git remote -v (to verify)
- git fetch upstream
- git checkout master (for master)
- git merge upstream/master (for master)
- git push origin master (for master)
- git checkout branchname (merge to)
- git merge branchname (merge from)
- git fetch origin
- git reset --hard origin/branch-name
- git clean -f -d
- For current branch:
git checkout
- git status
git stash push -m "message"
- Apply:
git stash apply stash@{index}
. For example:git stash apply stash@{1}
- git add .
- git commit -m "Commit Message"
- git push origin BranchName
- git reset filename
- git reset (for all the files)
- git reset --hard HEAD~ (hard or soft or mixed depending on the requirements)(For Latest commit) OR
- git reset --hard <last_working_commit_id> (for a specific commit)
- git push origin -f (To force push it to the remote)
- git branch --merged
- git branch -d (local branch)
- git push origin --delete (remote branch)
- git fetch --prune
- git remote prune upstream (for a specific remote)
- git checkout -- . (to checkout all the files)
- git checkout -- index.html (for a specific file)
- Fetch file from different branch:
git checkout master -- a.py
- git add --patch "file name"
- Stage this hunk [y,n,q,a,d,/,j,J,g,s,e,?]?
- https://stackoverflow.com/questions/1085162/commit-only-part-of-a-file-in-git
- :cq
- git merge --continue or git commit
- git push -u origin branch-name
- The equivalent long option is --set-upstream
- git fetch upstream pull/pr-number/head:pr-pr-number
- git checkout pr-pr-number
- https://demisx.github.io/git/rebase/2015/07/02/git-rebase-keep-my-branch-changes.html
- git rebase -Xtheirs master (rebase preferring current branch)
- git rebase -Xours master (rebase preferring master)
- git reset --hard origin/branch-name@{1}
- git push -f origin branch-name
- For more info: https://stackoverflow.com/questions/12568628/how-to-recover-from-a-git-push-force
git config --global --unset X
, where X is the name of the setting (remove global flag for repo level)- For instance:
git config --global --unset http.postBuffer
- For more info: https://stackoverflow.com/questions/50530583/resetting-git-config
** Akshat Bajaj, 2018**