Git Tips

Cross-Reference Issues

You can reference issues between repositories by mentioning user/repository#number in an issue.

Use emoji in your commits

Emoji Cheet Sheet

Issue references within a repository

Any number that refers to an Issue or Pull Request will be automatically converted into a link.

Things I Needed to Learn About Git

Quick Tip: Sync a Fork with the Original via GitHub's Web UI

git log --pretty=oneline 

source: Git Tags

How to undo (almost) anything with Git

Sometimes you need to revert the last commit, or a mass undo. Here is a good list of how to undo stuff. Also check out this site for more ways to fix your git problems.

Downloading Repositories

What happens when the repository owner has not prepared a zip file, and you just want a download to use yourself? There is an answer and you don't need to go though that horrid process to download software, install and register keys and whatnot on GitHub, etc.!

To simply download a repository as a zip file: add the extra path '/zipball/master/' to the end of the repository URL and voila, it gives you a zip file of the whole lot.

For example,

http://github.com/zoul/Finch/

becomes:

http://github.com/zoul/Finch/zipball/master/

It then gives you a zip file to download.

Delete Local Branches

git checkout master; git pull origin master; git fetch --all -p; git branch -vv | grep gone | awk '{ print $1 }' | xargs -n 1 git branch -d

Delete Local Branch after Merging

git checkout master
git merge --squash dev-branch
git status
git commit -m "merge current development branch"
Clean Up After Yourself
After the final merge from a branch, delete the branch from your local clone (prevents accidental usage).
git branch -D dev-branch
If you read the docs for git-branch, you'll see that you can use lowercase -d or uppercase -D to delete a branch. The former verifies that the branch has been merged before deleting it, the latter doesn't. Which means that if you squash your merges, Git won't let you use -d.

Add All Changes

If you want to stage all unstaged files and folders in your working directory you can also use the following shorthand:
git add .

See your settings

git config --list

Clone a remote repository

Change origin url

git remote set-url origin http//github.com/repo.git

Add remote

git remote add remote-name https://github.com/user/repo.git

See non-staged (non-added) changes to existing files

git diff
Note that this does not track new files.

See staged, non-commited changes

git diff --cached

See differences between local changes and master

git diff origin/master

See differences between two commits

git diff COMMIT1_ID COMMIT2_ID

See the files changed between two commits

git diff --name-only COMMIT1_ID COMMIT2_ID

See the files changed in a specific commit

git diff-tree --no-commit-id --name-only -r COMMIT_ID
or
git show --pretty="format:" --name-only COMMIT_ID

Revert one commit, push it

git revert dd61ab21
git push origin master

Revert to the moment before one commit

# reset the index to the desired tree
git reset 56e05fced
# move the branch pointer back to the previous HEAD
git reset --soft HEAD@{1}
git commit -m "Revert to 56e05fced"
# Update working copy to reflect the new commit
git reset --hard

Undo non-pushed commits

git reset origin/master

Reset to remote state

git fetch origin
git reset --hard origin/master

Create a tag

git tag 7.x-1.3

Push a tag

git push origin 7.x-1.3

Unstage (undo add) files:

git reset HEAD file.txt

This page contains information I gathered and thought were very useful. See more notes on development.

Just to let you know, this page was last updated Wednesday, Dec 11 24