My Git Notes


Typical git commands

git clone git@github.com:<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 git@github.com:<username>/<reponame>.git git remote set-url origin git@github.com:<username>/<reponame>.git git remote -v

Force git to overwrite local files on pull

git fetch --all<br>git reset --hard origin/master

1. downloads the latest from remote without trying to merge or rebase anything.

2. resets the master branch to what you just fetched

Tag version

Create tag

Delete tag, also remote


Set commit messages in modal text editor, like Vim


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

git clone <Your Public Clone URL>

	cd <Local-Repository>
	git remote add <remote-name> <Public Clone URL>
	git fetch <remote-name>

Fork

	git remote add <name> <Public Clone URL>
	git pull <name> master
	git push

Example

	$ git clone git@github.com:bueltge/wp-butler.git
	cd wp-butler
	git remote add upstream git://github.com/Japh/wp-butler.git
	git fetch upstream
	git pull upstream master
	git push

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)[http://stackoverflow.com/questions/927358/undo-the-last-git-commit]

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)[http://stackoverflow.com/questions/9646167/clean-up-a-fork-and-restart-it-from-the-upstream]

Submodule git commands

git submodule init git submodule update --recursive

Helpful .gitconfig Configurations

	[alias]
		a = !"git alias"
		c = commit
		s = status
		p = pull
		w = whatchanged
		rb = rebase
		# Rebase interactive
		rbi = !"git rebase -i"
		# Rebase interactive on our unpushed commits
		rbiu = !"git rebase -i @{u}"