My Git Notes

Typical git commands

git clone<user_name>/the-repo-you-are-cloning.git

git fetch upstream

git merge upstream/master

git add <file>

git status and git diff

git status -s

git commit -m 'the message goes here for the commit'

git add '*.<file_extension>'

git rm --cached <file>

git log

git log --summary

git reset <file>

git rebase

Work with branches

git branch -r

git remote <name> origin

git push origin --delete <branchName>

git checkout <target>

Work with Git Remote URL (URI)

git remote add origin<user_name>/<repo_name>.git

git remote set-url origin<user_name>/<repo_name>.git

git remote -v

Force git to overwrite local files on pull

git fetch --all
git reset --hard origin/master

Tag version

git tag
git tag -a v1.0 -m 'my version 1.0'
git push --tags

git tag -d v1.0
git push origin :refs/tags/v1.0

Set commit messages in modal text editor, like Vim

Fork & Merge changes from remote Github repository to your local repository


Rollback a git repository to a specific commit

git reset --hard <old-commit-id>>

git push -f <remote-name> <branch-name>

How to undo a local/public commit

git revert HEAD

git reset --soft HEAD^

More, check out StackOverflow 927358

Clean up a fork and restart it from the upstream

Using 'upstream' as the remote name referencing the original repo forked

More, check out StackOverflow 9646167

Submodule git commands

git submodule init

git submodule update --recursive

Helpful .gitconfig Configurations