Git Commands for beginners

Remove a commit:
Open terminal and go to your project directory then run command

git reset --soft HEAD^

This will remove your commit, running this command again and again will remove commit before that.

Revert a Pull request:

git revert SHAid

Remove all local changes

git fetch origin
git reset --hard origin/master

Find log for a file in all branches and commits

git log --all -- '**/data-upgrade-1.0.0-1.0.1.php 

Use custom/separate git config for repo
create .gitconfig file in root of repo and add in .gitignore
update git config to use local .gitconfig file

git config --file include.path ../.gitconfig

Delete all local branches that are already merged into the currently checked out branch

git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *