[Android Q&A, Help & Troubleshooting] MyComputerDoctor:
Working with GIT and GITHUB

for Android Source

I want to start by saying that I am no EXPERT on GIT, but I believe the best way to learn is through trial and error. Through my trials and errors, this is what I have found that works when working with Android Source Code (AOSP).

I started my Android Development basically porting and hacking Android Operating Systems for the HTC Thunderbolt. In my opinion I learned the basics plus some, and was able to create stable builds, which most users found enjoyable to operate. In my quest to further improve my Android development skills, I moved on the next step in Android Operating System development, build a custom AOSP ROM from source. I soon started browsing other developers GITHUB repositories and tried my best to figure out what was going on behind the scenes, in order to share my code with others and visa versa. This lead me to setting up a development platform, downloading the latest (at the time ICS) source and then compiling everything, to obtain, a fresh updated ROM. Obviously, the next step was editing the code to my liking and then trying to figure out how to update my code (push) to Github for version tracking and also hosting purposes. I shopped around on the net for GIT tutorials, and for the life of me, I could not figure out how to make things work the way they should. After doing research on the REPO command (which I came to find was basically the same as GIT but updated to work better with Android) I became more confused. I never found an article or tutorial which explained step-by-step the processes in which I am about to explain, which is why I decided to take the time to compose this tutorial.

Finally, through many hours of research and frustration, I came up with the answers I was so diligently seeking. Here are my findings:

The following Tutorial is for an INITIAL COMMIT of your source to GITHUB. Once you accomplish sending the initial data over, sending only changes thereafter, is very similar, but doesn't require as many steps.

Prerequisites:

(1) Create an account on GITHUB.com

(2) Download the Android Source into a working directory (in my case "android").

(3) Generate your Private SSH Keys for GITHUB (this will allow you to push files without logging in every time) You will find easy to understand directions HERE

For this example I will be working with the following variables:

My default Android directory: ~/android

For this tutorial I will editing the Setting.apk source code in order to add "XYZ" functionality

The source code for the Settings.apk is located in ~/android/packages/apps/Settings

So lets BEGIN!

First Step: You want to go into the directory where you are editing the source.

cd ~/android/packages/apps/Settings

Second Step: Initialize the Settings source folder and create a git repository

(which will track all changes)

git init

Third Step: Now you want to log-in to GITHUB and create a repository for your updated Settings source to go. In my case I created a folder on GUTHUB called android_packages_apps_Settings

Forth Step: After you have created your repository on GITHUB, from your Settings source folder, you need to tell git where to push the changes you have made. When you do the initial push, it is actually going to push all of the files in the Settings source folder including the changes you have made. Do this by typing the following command:

git remote add github git@github.com:yourusername/android_packages_apps_Settings.git

Obviously, you are going to change "yourusername" to whatever username you created on GITHUB.

Fifth Step: Add the entire Settings directory to git so that it starts tracking your additions, deletions, changes, etc for the entire directory.

git add -A

Sixth Step: Commit the changes that you made to the files in order to push to GITHUB. Now for this example, I want to commit changes to ALL files in the Settings folder.

git commit -a

If I wanted to just commit changes to one specific file, I would use "git commit whateverfile.java". After you commit, a text editor is going to pop-up. This is where you add the description for the change(s) you have made. If you have detailed change-log of each file you changed, you will not want to use the "git -a" command because the description you enter there is going to be the description for all of the files you edited.

Seventh Step: Now you want to change to the branch you plan on using to push your content. In my case its "jellybean".

git branch jellybean

Eighth Step: Finally you will now push your initial Settings commit to github. In order to do this, type:

git push github jellybean

This is going to push github ("github" is the name you gave the REMOTE when you executed the "git remote add" above) to a branch on GITHUB.com called "jellybean". You can name the branch whatever you like, but obviously naming it to the current Android release name is the easiest to remember for you and others.

You should now see that your computer sent files to GUTHUB.com and if you check online, you should see that your changes have been implemented and copied for the world to access.

I hope this helps people out with Android based git commands. I wish I found somthing like this months ago and maybe I would have a few extra hairs on my head. Let me know if you have any additional questions or would like me to add to this tutorial in any fashion. I will be doing a video shortly which I will post to this thread when complete.