Skip to content

Instantly share code, notes, and snippets.

@kirk86
Forked from leommoore/git_cheatsheet.md
Created October 29, 2015 19:25
Show Gist options
  • Save kirk86/40370b3147e4b4c0c12a to your computer and use it in GitHub Desktop.
Save kirk86/40370b3147e4b4c0c12a to your computer and use it in GitHub Desktop.
Git - Cheatsheet

#Git - Cheatsheet

###Create Repo git init

###Fork (Copy) existing Repo git clone repo name

###Branching You should create a branch per feature. Create a branch.

git branch CoolNewFeature

Switch to the new branch

git checkout CoolNewFeature <-- Now on the CoolNewFeature branch

Push branch to origin repo (optional). This branch will be stored separately on the repo.

git push origin CoolNewFeature

###Merging

When you are finished and want to merge back

git checkout master

git merge CoolNewFeature <-- This will merge into the current (master) from CoolNewFeature

If you encounter a bug which is fixed in another branch you can merge it into the current branch using:

git cherry-pick commit id

###Undo

git reset --hard ORIG_HEAD

git reset --hard HEAD

git checkout commit-id -- files...

###Comparing

git diff commit-id -- files...

git diff "master@{01-Sep-12}" -- files...

git blame files

git log files

###Deployment The master branch is normally assumed to be tested and production ready. For some projects it may be better to create a deployment branch to hold a particular version of the project. This is useful if the version needs to be maintained separately.

###Setting your commit editor When you do a commit you need to enter the details of what was done. This is important later if you want to keep track of what has changed without having to read all the code to figure out the differences from the previous commit. This can be done at the command line like this:

git commit -am "This is what has changed"

However, often the are more changes than can be conviently put in a one line entry. In this situation, it is useful to setup an editor to allow you to put in more detailed commit messages.

Linux - This will set gedit as your editor

git config --global core.editor "gedit"

Windows - This will set notepad as your editor

git config --global core.editor "notepad"

All you need to do is enter the message. ie

1. Added Home Screen
2. Fixed bug when use clicks on login button
etc...

Note: Many people recommend that you should do frequent commits. Some people prefer to commit after each change. Some people prefer to make a batch of related changes and then commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment