common git problems

Delete the remote branch

git push -d origin <branch_name>

Delete the local branch

git branch -D <branch_name>

Merge master into feature branch

git checkout master

git pull

git checkout feature

git merge master

Checkout from a specific commit

Use git checkout <sha1> to check out a particular commit

git checkout -b <branch> <commit>

Revert commit

git revert <commit_hash>

git revert <oldest_commit_hash>..<latest_commit_hash>

Setting your branch to exactly match the remote branch can be done in two steps:

git fetch origin

git reset –hard origin/master

Remove a file from PR

git checkout origin/master — src/main/java/

git commit -m “Removed files from PR”

Sync your fork with original

# Add a new remote upstream repository

git remote add upstream

# Sync your fork

git fetch upstream

git checkout master

git merge upstream/master

git remote add upstream <>

If you need to remove a single file from the staging area, use

git reset HEAD — <file>

Remove submodule dirty

git submodule foreach –recursive git checkout .

git submodule update –force –recursive –init –remote

About Hieu Nguyen

I am a Senior member of technical staff (Oracle, eBay, Microsoft) and a founder of iNest, LLC (an IoT company)
This entry was posted in git. Bookmark the permalink.