[Guide] How to use Github

Search This thread

Rick_1995

Inactive Recognized Developer
Sep 3, 2009
1,118
3,017
Santa Clara
To discard all unstaged changes e.g. failed merge etc. type:
Code:
git checkout .
# to delete all changes

git checkout path/to/file
# to discard changes for a specific file

I found it better to use "git reset --hard" if you want to reset the current git project completely, more often you might have extra files lurking around so in a dirty way you could do
Code:
rm -rf ./
git reset --hard
Thanks for a refreshing course in git :D


Tom,there's another way of force push,atleadt that's what I know.. :D
git push -u origin +branchtopushto

Afaik, -u is only used to set the upstream/remote repository to push/pull from.
 
Last edited:
  • Like
Reactions: eagleeyetom

eagleeyetom

Retired Senior Mod & DC Lead - Active Pole Dancer
Jan 22, 2011
7,709
14,677
37
Gdańsk
xda-developers.com
Samsung Galaxy Watch 4
I found it better to use "git reset --hard" if you want to reset the current git project completely, more often you might have extra files lurking around so in a dirty way you could do
Code:
rm -rf ./
git reset --hard
Thanks for a refreshing course in git :D




Afaik, -u is only used to set the upstream/remote repository to push/pull from.

Thanks. I'm going to add this in a free time :)

Sent from my X8 using xda premium
 

sert00

Senior Member
May 28, 2011
1,091
496
cesena,IT
oh my god man,it's what i'm looking for in last weeks!i'm beginning with compiling rom but not familiar with github and this,should make things be more easy for me,and sure for many many others people!thank you very much!appreciated!rated 5 stars and thanked!:laugh:
 

LinuxFrenzy

Member
Sep 7, 2012
11
2
Long Beach,CA
Thanks.I just recently got into compiling roms/kernels and this very much helps greatly since I am still new to the whole development world so this Guide is really helpful so once again thanks.
 

josuearisty

Senior Member
Dec 4, 2010
1,892
603
Somewhere!
Thanks for this guide, as soon as I fix my pc I will follow these steps, I really need to know how to compile roms and many other stuffs.
 

Vishal_Pratap singh

Senior Member
Jun 18, 2012
479
73
Gulbarga
At step 3.1 when I post the link in my terminal and run I get :No Such File or Directory
Every thing worked fine till then...


Sent from my GT-N7000 using xda app-developers app
 

Remoteconcern

Senior Member
May 27, 2011
769
292
Can anyone help? I'm trying to cherry pick. I don't understand how or where to resolve the conflicts after merging upstream branch.

Thanks in advance :)
 

jurben

Senior Member
Sep 10, 2012
155
51
thanks for great tutorial.

more information please...

there are global env command that affect every git run after everywhere like:
export GIT_SSL_NO_VERIFY=true

are there similar command that can substitute / override config entry:
git config core.filemode false

or is it this command ?
git config --global core.filemode false
 

TheGreatSega

Senior Member
Nov 12, 2011
635
854
Bangalore
Publickey perm denied

ok ive done everything

Code:
jsega@j:~$ ssh -vT git@github.com
OpenSSH_5.9p1 Debian-5ubuntu1, OpenSSL 1.0.1 14 Mar 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to github.com [207.97.227.239] port 22.
debug1: Connection established.
debug1: identity file /home/jsega/.ssh/id_rsa type 1
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: identity file /home/jsega/.ssh/id_rsa-cert type -1
debug1: identity file /home/jsega/.ssh/id_dsa type -1
debug1: identity file /home/jsega/.ssh/id_dsa-cert type -1
debug1: identity file /home/jsega/.ssh/id_ecdsa type -1
debug1: identity file /home/jsega/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.5p1 Debian-6+squeeze1+github8
debug1: match: OpenSSH_5.5p1 Debian-6+squeeze1+github8 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /home/jsega/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/jsega/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
Agent admitted failure to sign using the key.
debug1: Trying private key: /home/jsega/.ssh/id_dsa
debug1: Trying private key: /home/jsega/.ssh/id_ecdsa
debug1: No more authentication methods to try.
Permission denied (publickey).

but im getting this!! any solution??
 

gokussjx

Senior Member
Jul 7, 2011
2,061
4,910
/home/bidyut
ok ive done everything

Code:
jsega@j:~$ ssh -vT git@github.com
OpenSSH_5.9p1 Debian-5ubuntu1, OpenSSL 1.0.1 14 Mar 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to github.com [207.97.227.239] port 22.
debug1: Connection established.
debug1: identity file /home/jsega/.ssh/id_rsa type 1
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: identity file /home/jsega/.ssh/id_rsa-cert type -1
debug1: identity file /home/jsega/.ssh/id_dsa type -1
debug1: identity file /home/jsega/.ssh/id_dsa-cert type -1
debug1: identity file /home/jsega/.ssh/id_ecdsa type -1
debug1: identity file /home/jsega/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.5p1 Debian-6+squeeze1+github8
debug1: match: OpenSSH_5.5p1 Debian-6+squeeze1+github8 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /home/jsega/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/jsega/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
Agent admitted failure to sign using the key.
debug1: Trying private key: /home/jsega/.ssh/id_dsa
debug1: Trying private key: /home/jsega/.ssh/id_ecdsa
debug1: No more authentication methods to try.
Permission denied (publickey).

but im getting this!! any solution??


You've generated the SSH Public key, & added it to Git, I suppose?
If not, you should do it first.
If you already have.. hmm, then your keys are not properly added.
 
Last edited:

Top Liked Posts

  • There are no posts matching your filters.
  • 360
    Hi.
    Today I would like to show you how to use github. I'm not an expert (I'm rather n00b TBH :p) 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.

    c826ad7b.png


    2. Creating an account.

    • 2.0 Download the required libs
      Code:
      sudo apt-get install git
    • 2.1 Create an account on github.com website
    • 2.2 In terminal type:
      Code:
      git config --global user.name "Your Name Here"
      git config --global user.email "your_email@youremail.com"

      NOTE: use the e-mail used in the website account creation
      2.3 Create your unique SSH public key
      Code:
      ssh-keygen -t rsa -C "your_email@youremail.com"
      # 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.
      Code:
      # Enter passphrase (empty for no passphrase): [Type a passphrase]
      # Enter same passphrase again: [Type passphrase again]

      Which should give you something like this:
      Code:
      # Your identification has been saved in /c/Users/you/.ssh/id_rsa.
      # Your public key has been saved in /c/Users/you/.ssh/id_rsa.pub.
      # The key fingerprint is:
      # 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@youremail.com

      Now go to ~/.ssh folder and copy your id_rsa.pub content into account administration on github.com
      7326e529.png


      ... and check if everything works

      Code:
      ssh -T git@github.com
      Code:
      The authenticity of host 'github.com (207.97.227.239)' 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!

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

    And we are ready to do some serious things! :highfive:

    3. Forking a repo

    As an example I'll use https://github.com/CyanogenMod/android_packages_apps_Settings
    Open this link in the browser and click fork.

    3a2b3915.png


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

      Code:
      git clone git://github.com/eagleeyetom/android_packages_apps_Settings.git -b gingerbread

      -b gingerbread let us to choose what branch are we going to download

      d8305e5d.png

    • 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:
      Code:
      git branch xda
      git checkout xda

      Now it's time to see what's going on:
      Magic command
      Code:
      git status

      987e44ce.png


      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:
      Code:
      git add .

      Add all removed files
      Code:
      git add -u

      You can also add/rm one file
      Code:
      git add name_of_file
      git rm name_of_file

      After git status we should get something like this:

      cda04609.png


      Now it's time to commit:

      Code:
      git commit -m 'my first commit'

      And finally to push:

      Code:
      git push

      If you'll get some errors use the following:

      Code:
      git push git@github.com:eagleeyetom/android_packages_apps_Settings.git xda
      I used the name of my github and the name of the branch in the end.

      f4c5b1cf.png


      Woo hoo! Now let's check the website.

      a123383f.png

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

    Credits:
    Google :D
    Github Team
    All my friends from GingerDX IRC channel

    If you find it useful hit thanks button. You can also consider a small donation ;)
    158
    5. Removing branch.
    This one took me a lot of googleing and many bad words has been said :p

    I'll make a test branch 'deleteme'

    Code:
    git branch deleteme
    git checkout deleteme
    git push git@github.com:eagleeyetom/android_packages_apps_Settings.git deleteme

    And I have new remote branch now.
    But I want to delete it.
    Here's the answer.
    First:
    Check the branches:
    Code:
    git branch -a
    And I'll get:
    Code:
      remotes/origin/HEAD -> origin/gingerbread
      remotes/origin/deleteme
      remotes/origin/donut
      remotes/origin/eclair
      remotes/origin/froyo
      remotes/origin/froyo-stable
      remotes/origin/gb-release-7.2
      remotes/origin/gingerbread
      remotes/origin/gingerbread-release
      remotes/origin/ics
      remotes/origin/icsify
      remotes/origin/wip
      remotes/origin/xda

    I want to delete this branch.
    Type:
    Code:
    git branch -rd origin/deleteme
    # Deleted remote branch origin/deleteme (was 808ffbb).
    Code:
    git push git@github.com: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:
    Code:
    git remote add upstream https://github.com/MiniCM/android_packages_apps_Settings.git

    Download the branch:
    Code:
    git fetch upstream
    Code:
    * [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:
    <<<<<<<<
    =======
    >>>>>>>>
    symbols.

    Don't forget to test make before pushing!

    Now standard procedure:
    Code:
    git add .
    git commit -m 'test merge'
    git push git@github.com: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.
    Code:
    git remote add upstream https://github.com/MiniCM/android_packages_apps_Settings.git
    git fetch upstream
    git cherry-pick c95854e8c91ec279bd3719c637f531491855278a

    And we're good :highfive:
    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.
    Code:
    git checkout -t remote_name/remote_branch
    It allows you to change the branch to remote one without cloning the whole repo again.
    124
    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.

    ca9c75ac.png


    Then choose the account and branch to pull-request.

    e72882aa.png


    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

    be8d06e7.png


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

    f927eafa.png


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

    4c803a33.png


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

    You can also use text method:

    Code:
    git checkout master
    [COLOR="DeepSkyBlue"]# Check out your master branch[/COLOR]
    git remote add TeamFun git://github.com/TeamFun/android_packages_apps_Settings.git
    [COLOR="deepskyblue"]# Add a new remote named 'TeamFun'[/COLOR]
    git fetch TeamFun
    [COLOR="deepskyblue"]# Pull in all the commits from the 'cameronmcefee' remote[/COLOR]
    git merge TeamFun/gingerbread
    [COLOR="deepskyblue"]# Merge your master branch into the 'gingerbread' branch from the 'TeamFun' remote[/COLOR]
    git push git@github.com:eagleeyetom/android_packages_apps_Settings.git master
    [COLOR="deepskyblue"]# Push your newly-merged branch back to GitHub[/COLOR]

    or

    Code:
    git checkout master
    [COLOR="DeepSkyBlue"]# Check out your master branch[/COLOR]
    $ curl http://github.com/octocat/Spoon-Knife/pull/25.patch | git am
    [COLOR="deepskyblue"]# Grab the patch generated by a pull request and feed it into a new commit[/COLOR]
    $ git push git@github.com:eagleeyetom/android_packages_apps_Settings.git master
    [COLOR="deepskyblue"]# Push your newly-updated commit back to GitHub[/COLOR]

    TIPS AND TRICKS

    REVERT CHANGES

    To discard all unstaged changes e.g. failed merge etc. type:
    Code:
    git checkout .
    # to delete all changes
    
    git checkout path/to/file
    
    # to discard changes for a specific file

    You can also use:
    Code:
    rm -rf ./ 
    
    [COLOR="Cyan"]# deletes all of the files in the directory[/COLOR]
    
    git reset --hard
    
    [COLOR="cyan"]#This is going to restore the git to the previous state[/COLOR]

    HOW TO REMOVE COMMITTED CHANGES?

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

    Code:
    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.

    GIT PATCH AND GIT APPLY

    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.
    Code:
    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

    Code:
    git show 22a95d1 > patchname.patch

    And I got patch, but how to apply it?
    The answer is easy. Use git apply.

    Code:
    git apply patchname.patch
    # --check checks if the patch can be applied

    FORCE PUSH
    Sometimes github doesn't want to cooperate - just like some people :D
    You can force it by adding --force or -f
    Code:
    git push -f git@github.com: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
    3
    Stickied this...

    good learning guide to show people how to use github when starting out for sure. :)
    3
    First of all, I'm new to this :D
    I setup everything according to the tutorial.
    Now I'm upstreaming sony 2011 stock kernel 2.6.32.9 on local repo and I want to sync changes to github repo.
    Acording to "git status" command I've modified and deleted files.
    should I use this command " git add . " then " git add -u"
    or just "git add ." ??
    Excuse me for being noob , Just want to make sure that I do the right thing.
    Thanks in advance.

    You should execute both commands. And no need to apologize, mate :) We're here to learn :)