[Guide] How to use Github

7,712 posts
Thanks Meter: 15,984
By eagleeyetom, Retired Developer Committee Lead / Retired Senior Moderator / Active Pole Dancer on 8th September 2012, 08:32 PM
Post Reply Email Thread
Today I would like to show you how to use github. I'm not an expert (I'm rather n00b TBH ) but I learned some things and might help you with simple git commands.

1. Github? What's that?

In short it's the web-based hosting service for software development projects that use the Git revision control system. In English - the place where you store your sources.

2. Creating an account.
  • 2.0 Download the required libs
    sudo apt-get install git
  • 2.1 Create an account on website
  • 2.2 In terminal type:
    git config --global "Your Name Here"
    git config --global "[email protected]"
    NOTE: use the e-mail used in the website account creation
    2.3 Create your unique SSH public key
    ssh-keygen -t rsa -C "[email protected]"
    # Creates a new ssh key using the provided email
    # Generating public/private rsa key pair.
    # Enter file in which to save the key (/c/Users/you/.ssh/id_rsa): [Press enter]
    Now you need to enter a passphrase.
    # Enter passphrase (empty for no passphrase): [Type a passphrase]
    # Enter same passphrase again: [Type passphrase again]
    Which should give you something like this:
    # Your identification has been saved in /c/Users/you/.ssh/id_rsa.
    # Your public key has been saved in /c/Users/you/.ssh/
    # The key fingerprint is:
    # 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db [email protected]
    Now go to ~/.ssh folder and copy your content into account administration on

    ... and check if everything works

    ssh -T [email protected]
    The authenticity of host ' (' can't be established.
    # RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
    # Are you sure you want to continue connecting (yes/no)?
    Duh?! Sure I want! Yes! Yes! Yessss!

    # Hi username! You've successfully authenticated, but GitHub does not
    # provide shell access.

And we are ready to do some serious things!

3. Forking a repo

As an example I'll use
Open this link in the browser and click fork.

  • 3.1 Clone the source from your fork.
    I use my account as an example.

    git clone git:// -b gingerbread
    -b gingerbread let us to choose what branch are we going to download

  • 3.2 Do some changes!

    For example add files, remove them etc.
  • 3.3 Commit the changes

    OPTIONAL I created new branch at my project and named it "xda"
    To do this go to the cloned folder and type:
    git branch xda
    git checkout xda
    Now it's time to see what's going on:
    Magic command
    git status

    As you can see I removed few files and added one.

    Now it's time to tell the git what we want to do.

    4. Pushing the changes

    Add all modified files:
    git add .
    Add all removed files
    git add -u
    You can also add/rm one file
    git add name_of_file
    git rm name_of_file
    After git status we should get something like this:

    Now it's time to commit:

    git commit -m 'my first commit'
    And finally to push:

    git push
    If you'll get some errors use the following:

    git push [email protected]:eagleeyetom/android_packages_apps_Settings.git xda
    I used the name of my github and the name of the branch in the end.

    Woo hoo! Now let's check the website.

That's the most basic basics
In the next posts I will show you some more advanced commands like merge, cherry-pick, removing branches etc.

Github Team
All my friends from GingerDX IRC channel

If you find it useful hit thanks button. You can also consider a small donation
The Following 368 Users Say Thank You to eagleeyetom For This Useful Post: [ View ] Gift eagleeyetom Ad-Free
8th September 2012, 08:38 PM |#2  
eagleeyetom's Avatar
OP Retired Developer Committee Lead / Retired Senior Moderator / Active Pole Dancer
Flag Gdańsk
Thanks Meter: 15,984
Donate to Me
5. Removing branch.
This one took me a lot of googleing and many bad words has been said

I'll make a test branch 'deleteme'

git branch deleteme
git checkout deleteme
git push [email protected]:eagleeyetom/android_packages_apps_Settings.git deleteme
And I have new remote branch now.
But I want to delete it.
Here's the answer.
Check the branches:
git branch -a
And I'll get:
  remotes/origin/HEAD -> origin/gingerbread
I want to delete this branch.
git branch -rd origin/deleteme
# Deleted remote branch origin/deleteme (was 808ffbb).
git push [email protected]:eagleeyetom/android_packages_apps_Settings.git :refs/heads/deleteme
And the remote branch is gone! Yeah!

6. Merging the commits
Imagine the situation that you want to add a commits created by someone else. Let's use our great Recognized Developer nobodyAtall

We need to add the source:
git remote add upstream
Download the branch:
git fetch upstream
* [new branch]      cm-9.0.0   -> upstream/cm-9.0.0
 * [new branch]      donut      -> upstream/donut
 * [new branch]      eclair     -> upstream/eclair
 * [new branch]      froyo      -> upstream/froyo
 * [new branch]      froyo-stable -> upstream/froyo-stable
 * [new branch]      gb-release-7.2 -> upstream/gb-release-7.2
 * [new branch]      gingerbread -> upstream/gingerbread
 * [new branch]      gingerbread-release -> upstream/gingerbread-release
 * [new branch]      ics        -> upstream/ics
 * [new branch]      jellybean  -> upstream/jellybean
 * [new branch]      master     -> upstream/master
 * [new branch]      wip        -> upstream/wip

You'll get a message to resolve the conflicts. In short and most n00b friendly way is to open pointed files and delete the:

Don't forget to test make before pushing!

Now standard procedure:
git add .
git commit -m 'test merge'
git push [email protected]:eagleeyetom/android_packages_apps_Settings.git xda
7. Cherry-pick the single commit
Now it's time to add specific commit to our build. I'm going to use this one.
git remote add upstream
git fetch upstream
git cherry-pick c95854e8c91ec279bd3719c637f531491855278a
And we're good
Now commit should be added. All you need now is to push - no need to commit

8. Changing the branch
While using git you may noticed that sometimes after fresh sync there is no branch selected. Imagine the situation when you are on a branch A and want to check to branch B, because it uses a different method (like framework patch etc.)
The solution is pretty simple.
git checkout -t remote_name/remote_branch
It allows you to change the branch to remote one without cloning the whole repo again.
The Following 160 Users Say Thank You to eagleeyetom For This Useful Post: [ View ] Gift eagleeyetom Ad-Free
8th September 2012, 08:39 PM |#3  
eagleeyetom's Avatar
OP Retired Developer Committee Lead / Retired Senior Moderator / Active Pole Dancer
Flag Gdańsk
Thanks Meter: 15,984
Donate to Me
Pull request

If you feel that you have fixed a problem and want to help the developer to make his own ROM/kernel etc. you should consider to make a pull request. Pull request adds the changes you have made to the others repo.

First of all.
Fork and clone destined repo.
Check the previous post about forking and cloning.
Now make some changes and upload it to your own remote git.

Then, go to your forked repo using browser and click on Pull request.

Then choose the account and branch to pull-request.

Click and wait for your request to be merged

Merging a pull request.
Sometimes someone wants to add something to your code.
You'll be notified by e-mail and also see the notification on your github website.

Go there and click Open

When the changes can't be merged you'll see such message:

But when it's green, you are ready to merge it

Don't forget to review the code. In other way you'll be forced to delete the commit.

You can also use text method:

git checkout master
# Check out your master branch
git remote add TeamFun git://
# Add a new remote named 'TeamFun'
git fetch TeamFun
# Pull in all the commits from the 'cameronmcefee' remote
git merge TeamFun/gingerbread
# Merge your master branch into the 'gingerbread' branch from the 'TeamFun' remote
git push [email protected]:eagleeyetom/android_packages_apps_Settings.git master
# Push your newly-merged branch back to GitHub

git checkout master
# Check out your master branch
$ curl | git am
# Grab the patch generated by a pull request and feed it into a new commit
$ git push [email protected]:eagleeyetom/android_packages_apps_Settings.git master
# Push your newly-updated commit back to GitHub


To discard all unstaged changes e.g. failed merge etc. type:
git checkout .
# to delete all changes

git checkout path/to/file

# to discard changes for a specific file
You can also use:
rm -rf ./ 

# deletes all of the files in the directory

git reset --hard

#This is going to restore the git to the previous state

To remove committed changes you have to revert the commit. But how to do that? It's your answer

git reset HEAD --hard
HEAD is the previous commit. To revert to previous state use HEAD~1, HEAD~2 etc. you can also use the code taken from git log.


Now I want to make a patch file to e.g. send an e-mail with my commited changes.

First I need to find a changes made by a commit. To do this I need to know commit ID.
git log --oneline #This would show the commit ID's
Now pick the commit for example 22a95d1 and use git show to make a patch

git show 22a95d1 > patchname.patch
And I got patch, but how to apply it?
The answer is easy. Use git apply.

git apply patchname.patch
# --check checks if the patch can be applied
Sometimes github doesn't want to cooperate - just like some people
You can force it by adding --force or -f
git push -f [email protected]:eagleeyetom/android_packages_apps_Settings.git master
n00b method to add changes after failed push.
Clone the repo and delete everything but .git directory. Then copy modified content, commit and push :P
The Following 125 Users Say Thank You to eagleeyetom For This Useful Post: [ View ] Gift eagleeyetom Ad-Free
8th September 2012, 08:55 PM |#5  
Chris95X8's Avatar
Senior Member
Thanks Meter: 2,298
Oh I needed this. Thanks EET!
The Following User Says Thank You to Chris95X8 For This Useful Post: [ View ] Gift Chris95X8 Ad-Free
9th September 2012, 01:47 AM |#6  
RohinZaraki's Avatar
Senior Member
Thanks Meter: 3,795
Thanks man really needed this !
9th September 2012, 03:02 AM |#7  
lucastan96's Avatar
Senior Member
Flag Malacca
Thanks Meter: 2,116
Wow... this is also exactly what I would want! Thanks EET!

SEARCH. ASK. TEST... not the other way round! - lucastan96

Sent With My Brains To Yours
9th September 2012, 06:28 AM |#8  
cascabel's Avatar
Senior Member
a city in a galaxy far far away
Thanks Meter: 874
Great. Now i'll know what i'm doing wrong. :thumbup:

Please give credit where credit is due..
If you can't even search how can I help you??
9th September 2012, 07:13 AM |#9  
HashyCode's Avatar
Senior Member
Flag Cheras
Thanks Meter: 2,199
Thanks bro needed this !
9th September 2012, 07:43 AM |#10  
AndroXperia's Avatar
Junior Member
Flag Selangor
Thanks Meter: 1
Wow... this is what i exactly learning too ! Thanks mate...

my current stage
repo branching and remote branching
im using merging conflict Kdiff3(downloaded from website)
  1. Add the KDiff3 directory to your Windows System Path (e.g. C:\Program Files\KDiff3\)
  2. Add kdiff3 as your Git mergetool (From Git Bash, run git config --global merge.tool kdiff3)
  3. Add kdiff3 complete path to Git Config
    (From Git Bash, run git config --global mergetool.kdiff3.path "C:/Program Files/KDiff3/kdiff3.exe")
  4. Go into Git GUI settings and set the mergetool to kdiff3 (if Git GUI doesn't pick up this setting from git config, which it should)

git config --global diff.tool KDiff3

git config --global difftool.KDiff3.path "C:/Program Files/KDiff3/kdiff3.exe"

git config --global merge.tool KDiff3

git config --global mergetool.KDiff3.path "C:/Program Files/KDiff3/kdiff3.exe"

then type,

git mergetool

it will auto bring to your Kdiff3
The Following User Says Thank You to AndroXperia For This Useful Post: [ View ] Gift AndroXperia Ad-Free
9th September 2012, 08:18 AM |#11  
manoranjan2050's Avatar
Senior Member
Thanks Meter: 1,425
Donate to Me
Great guide.......

Sent from my GT-S6102 using Tapatalk 2
Post Reply Subscribe to Thread

git, github, guide, pull request

Guest Quick Reply (no urls or BBcode)
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes