If you're a programmer, these 10 git commands will save you hours of research🧵👇
Pull from remote overwriting local changes.
i) git stash (revert and stash changes locally)
ii) git pull (pull from remote normally)
tip: to retrieve changes, do 'git stash apply'
i) git stash (revert and stash changes locally)
ii) git pull (pull from remote normally)
tip: to retrieve changes, do 'git stash apply'
Delete only untracked files from working tree
git clean -f -d
git clean -f -d
Unstage files from index (but keep the files locally)
git rm --cached
git rm --cached
Undo a merge
i) git checkout branch-name
ii) git log --oneline
iii) git revert -m commit-id
i) git checkout branch-name
ii) git log --oneline
iii) git revert -m commit-id
Remove a file from remote
i) git rm filename (remove file from git)
ii) git commit -m "commit message"
iii) git push
i) git rm filename (remove file from git)
ii) git commit -m "commit message"
iii) git push
Undo last n commits
git reset --soft HEAD^n (where n is the number of last commits you want to undo)
git reset --soft HEAD^n (where n is the number of last commits you want to undo)
See diff between branches
git diff branch_1..branch_2
git diff branch_1..branch_2
Remove a tag from branch
i) git push origin :refs/tags/tagname
ii) git tag -d
i) git push origin :refs/tags/tagname
ii) git tag -d
Rename a branch locally & remote
i) git checkout old-branch
ii) git branch -m new-name
iii) git push origin :old-name new-name
i) git checkout old-branch
ii) git branch -m new-name
iii) git push origin :old-name new-name
Move existing, uncommitted work to a new branch
git switch -c <new-branch> (git 2.3 onwards)
git switch -c <new-branch> (git 2.3 onwards)
That's all for this thread. If you find this useful:
1. Retweet and leave a like on the first tweet - it encourages me to write more of similar content.
2. Follow me @ujjwalscript for more useful tips and threads 🙂
1. Retweet and leave a like on the first tweet - it encourages me to write more of similar content.
2. Follow me @ujjwalscript for more useful tips and threads 🙂
Loading suggestions...