[Android General] MSF Jarvis:
Github being the world's biggest code hosting platform is also an OSS powerhouse. Their most under popularised creation is hub.

According to the official website, "hub helps you win at git". I'll be covering the installation and use below, and we shall see if we win or not ;)

Installation

Installation is clean and easy. Download the latest release from https://github.com/github/hub/releases and unzip the archive. You should see the following files

.:
bin etc install LICENSE README.md share

./bin:
hub

./etc:
hub.bash_completion.sh hub.zsh_completion README.md

./share:
man

./share/man:
man1

./share/man/man1:
hub.1

Executing a simple ./install will install the hub binary, the man pages, and the hub+git bash completion script. You need to do one additional step before you're ready to use hub. Add alias git=hub to your .bashrc and then save it. Now every new terminal is ready to use hub, by using our good old git invocation.

Before adding the alias :

harsh@jarvis:~$ git
usage: git [--version] [--help] [-C <path>] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)
clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)
add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index

examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status

grow, mark and tweak your common history
branch List, create, or delete branches
checkout Switch branches or restore working tree files
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
merge Join two or more development histories together
rebase Forward-port local commits to the updated upstream head
tag Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)
fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects

'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.

After adding the alias:

harsh@jarvis:~$ git
usage: git [--version] [--help] [-C <path>] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)
clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)
add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index

examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status

grow, mark and tweak your common history
branch List, create, or delete branches
checkout Switch branches or restore working tree files
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
merge Join two or more development histories together
rebase Forward-port local commits to the updated upstream head
tag Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)
fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects

'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.

These GitHub commands are provided by hub:

pull-request Open a pull request on GitHub
fork Make a fork of a remote repository on GitHub and add as remote
create Create this repository on GitHub and add GitHub as origin
browse Open a GitHub page in the default browser
compare Open a compare page on GitHub
release List or create releases (beta)
issue List or create issues (beta)
ci-status Show the CI status of a commit

You will see the second code snippet has some additional commands listed. We'll be going over all of these shortly.

Functionality

hub lets you simplify your clone commands. To clone your own repos, just specify the repo name, as in git clone local_manifests

harsh@jarvis:~$ git clone local_manifests
Cloning into 'local_manifests'...
remote: Counting objects: 69, done.
remote: Total 69 (delta 0), reused 0 (delta 0), pack-reused 69
Receiving objects: 100% (69/69), 8.55 KiB | 0 bytes/s, done.
Resolving deltas: 100% (23/23), done.
Checking connectivity... done.
harsh@jarvis:~$ cd local_manifests/
harsh@jarvis:~/local_manifests$ git remote -v
origin	git@github.com:MSF-Jarvis/local_manifests.git (fetch)
origin	git@github.com:MSF-Jarvis/local_manifests.git (push)

To clone someone else's repo, just add the username to it

harsh@jarvis:~$ git clone regalstreak/skadoosh
Cloning into 'skadoosh'...
remote: Counting objects: 176, done.
remote: Compressing objects: 100% (23/23), done.
remote: Total 176 (delta 10), reused 0 (delta 0), pack-reused 153
Receiving objects: 100% (176/176), 27.75 KiB | 0 bytes/s, done.
Resolving deltas: 100% (67/67), done.
Checking connectivity... done.
harsh@jarvis:~$ cd skadoosh/
harsh@jarvis:~/skadoosh$ git remote -v
origin	git@github.com:regalstreak/skadoosh.git (fetch)
origin	git@github.com:regalstreak/skadoosh.git (push)

All standard switches are supported as well, so you can pass -b cm-13.0 with the clone command.

hub also makes forking a very easy task, simply type git fork in a cloned repository's folder

harsh@jarvis:~/skadoosh$ git fork
Updating MSF-Jarvis
From ssh://github.com/regalstreak/skadoosh
* [new branch] lol2 -> MSF-Jarvis/lol2
* [new branch] lolita -> MSF-Jarvis/lolita
new remote: MSF-Jarvis
harsh@jarvis:~/skadoosh$ git remote -v
MSF-Jarvis	git@github.com:MSF-Jarvis/skadoosh.git (fetch)
MSF-Jarvis	git@github.com:MSF-Jarvis/skadoosh.git (push)
origin	git@github.com:regalstreak/skadoosh.git (fetch)
origin	git@github.com:regalstreak/skadoosh.git (push)

git fork --no-remote will fork the repo but will not add a remote as it did in the earlier example.

Another powerful feature of hub is the ability to create Pull Requests from the terminal. Here you can see me adding a commit to [MENTION=5325978]regalstreak[/MENTION]'s automated ROM source compression script

harsh@jarvis:~/skadoosh$ nano compress.bash
harsh@jarvis:~/skadoosh$ git status
On branch lolita
Your branch is up-to-date with 'origin/lolita'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: compress.bash

no changes added to commit (use "git add" and/or "git commit -a")
harsh@jarvis:~/skadoosh$ git add -A
harsh@jarvis:~/skadoosh$ git commit -asm "Exodus 6.0"

You need a passphrase to unlock the secret key for
user: "Harsh Shandilya (MSF Jarvis) <msfjarvis@gmail.com>"
4096-bit RSA key, ID A950D459, created 2016-08-21

[lolita 6972288] Exodus 6.0
1 file changed, 3 insertions(+), 3 deletions(-)
harsh@jarvis:~/skadoosh$ git push MSF-Jarvis lolita
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 1014 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To git@github.com:MSF-Jarvis/skadoosh.git
aeff4d3..6972288 lolita -> lolita

I pushed this commit to my fork of the repo (I could have pushed directly as well, I'm a contributor ;) ). Now we'll see how to start a PR from MSF-Jarvis/skadoosh to regalstreak/skadoosh, from the terminal.

To start a PR, use the following command

harsh@jarvis:~/skadoosh$ git pull-request -h MSF-Jarvis:lolita -b regalstreak:lolita
https://github.com/regalstreak/skadoosh/pull/33

This command brings up a PR message editor that behaves much like the commit message editor we see all the time. Fill in and hit enter :)

create lets you, umm, create a new github repository from the current local repository. create also accepts some flags, which you'll see below

harsh@jarvis:~/hub-rocks$ git status
On branch master
nothing to commit, working directory clean
harsh@jarvis:~/hub-rocks$ git create -p -d "Super secret stuff here" hub-rocks
Updating origin
created repository: MSF-Jarvis/hub-rocks
harsh@jarvis:~/hub-rocks$ git push -u origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 897 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:MSF-Jarvis/hub-rocks.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.

the 'hub-rocks' at the end is the repository name, which defaults to the current directory name, and goes up the folder structure until a folder name is found that does not match the name of an existing repository.

The created repo

browse lets you visit specific pages of any repo

git browse MSF-Jarvis/android_device_google_seedmtk commits

will open the commits view of my device tree repo for seedmtk

git browse regalstreak/skadoosh pulls

will show the PRs on [MENTION=5325978]regalstreak[/MENTION]'s skadoosh repo, and so on.

compare is a pretty straight-forward command, to show a webpage with the diff between two tags, commits, or branches or a permutation of both.

harsh@jarvis:~/skadoosh$ git compare -u MSF-Jarvis lolita..lol2

will compare the lolita and lol2 branches on my fork of regalstreak/skadoosh

release lets you create a new release on your repository and also adds tags, and uploads assets.

harsh@jarvis:~/git-repos/reg-api$ git release create -a app.py v1.0
Uploading assets (1/1)
https://github.com/MSF-Jarvis/reg-api/releases/tag/v1.0

Which results in

issue works in a similar way

harsh@jarvis:~/git-repos/reg-api$ git issue create -m "No authorisation enforced on endpoints" -l BUG,Will\ be\ fixed,Enhancement
https://github.com/MSF-Jarvis/reg-api/issues/1

Result

ci-status will show the Travis-CI response code for the latest commit on the repo and may return one of, success, pending, failure. On repos where CI has not been enabled, this returns a 404.

This is just a minor introduction to the things hub can do for you. Play around, and you'll find some more hidden goodies ;)