[Android] akhilnarang:
How To Use Git!

Now, to explain about git

Its a version control system, for code, like mercurial or subversion

Most android source code is either at AOSP

Most custom ROMs like CyanogenMod,Radium, host their code over at GitHub

So to start off, make a GitHub Account! :D

Here, you will find all the various repositories, full of code :P

All files are stored in repositories

When browsing a repository, you will see a button called fork

This will make a copy of it in your account, so you can edit it, and even submit changes for approval to the parent account

Now, to download the source of a repository onto your computer, we use git clone command

$ git clone https://github.com/akhilnarang/scripts

So we download the scripts from my github onto your PC, so we can run them

Now, if you added your ssh key as shown in bottom of post #1, then when cloning a repo from your account, while copying the link from bottom right corner, choose ssh link.

If you, when pushing(uploading)local changes, you will not be prompted for username and password, your ssh key will identify you :P.

After cloning, cd to the directory

Run

git remote -v

This will show a list of remotes

Default is origin, i.e. the link you have cloned from

Now once we make our changes locally

$ git add -A

This stages all modified/added/deleted files to be committed

$ git commit

This opens a text editor for you to write a commit message for your commit

Just give me brief description of your changes or something :v.

Then

$ git push <remote-name> HEAD:<branch>

If you have cloned, then remote will be origin

Branch can be checked by

git branch

, and also online from where you cloned

If you used https:// URL then you will be prompted for username and password to authenticate yourself

If git:// URL you can't push, you will need to use a https:// or ssh link

Another way to push can be

$ git push <link> HEAD:<branch>

Now say you want to make your own git repository of your files

Click on the new repository button on GitHub, give a name

You can do initial commit online, or locally

Follow the instructions it gives you

i.e. if you have all files ready (in a folder)

$ git init
$ git add -A
$ git commit
$ git push <link> HEAD:<branch>

A VERY important thing to be noted while using version control systems like git, is to preserve authorship of a commit

If someone else has made some changes to a file, and we want them, we should not copy the changes and commit, but should give them authorship either by cherry-picking(will be explained)

Or using this syntax

$ git commit --author="Author Name <authoremail@blah.com>"

Through this git will know the correct authors

Not giving proper authorship is known as kanging, not appreciated here on XDA,(or anywhere else for that matter), and can cause you to be banned :3

Anyway, on to cherry-picking

Go to your repository

$ git remote add blahblah link-to-url-you-want-commit-from
$ git fetch blahblah branch-commit-is-on
$ git cherry-pick Commit-sha1-hash

If you see a commit on GitHub, or GitLab, or BitBucket, there is a unique(to that repo) SHA for every commit to identify it

Fetch the correct repo as shown above, and paste the commit id

That will fetch the changes

However, if your local source is quite different from the source you cherry-picked from, it will conflict

If so your terminal will display it

then run

$ git status

Files shown in red color have conflicts

Open them with a text editor like Atom(my favorite), nano, gedit, vim, etc

Look for <<<<<<<

From there, the content till ======

is the original content

=======

till >>>>>>> *insert commit message here* is the new stuff

So check the commit, figure out what's wrong, fix it, save.

Then

$ git add -A
$ git commit

If no conflicts it will commit on its own and you just need to

$ git push

as explained earlier :v

Running

$ git log

will show you a list of commits :D, authors, and SHA

If for some reason you wanna remove some commit, use

$ git revert commit-SHA

Just like cherry-picks, it may have conflicts :P

Anyway, this is just a small guide to get started off

You can easily found out more by searching, and experimenting

I will add more stuff here soon

Enjoy with this much till then :P