The terminal is a text interface for asking your computer to run programs. Git records and compares project states. Android source work uses both constantly, but you do not need hundreds of commands. This lesson uses a uniquely created practice folder and local Git only.
Before you start#
- What is Android?
- Workstation setup — choose a host route and verify Git.
Learning goals#
You can identify the current directory, explain each part of a shell command, create a new practice directory without reusing existing work, distinguish redirected output from a pipe, and predict the difference between untracked, staged, and committed Git changes.
First, read the command line#
Examples are for Bash in Ubuntu 22.04 x86_64; WSL Ubuntu uses Bash in its Linux environment. They are not PowerShell instructions. In a code block, type the command only—not a $ prompt or explanatory text. Press Enter and wait. Normal output may be blank; the shell prompt returning means that command finished. If you see an error, stop, note the exact message, and compare assumptions; do not add sudo or guess a destructive “fix.” A running command can usually be interrupted with Ctrl+C, but first know whether it is changing data.
A command has a program and often arguments. In ls -l /tmp, ls is the program, -l an option, /tmp a directory argument. A path names a filesystem location. / is the filesystem root; . means current directory and .. its parent. Linux names are case-sensitive (Notes.md differs from notes.md). The prompt may show the current directory but is customizable; it is not command text.
Host — Ubuntu Bash, read-only inspection:
pwd
ls
pwd prints the current directory; ls lists entries. Your output depends on your computer. For example, pwd might print /home/learner; the listing might be empty or contain files. If either command is missing, you are likely not in the documented shell or your environment is unusual—stop and check Workstation setup.
Make a genuinely new practice directory#
- producer | consumer
- producer stdout → consumer stdin. No output file is created by the pipe itself.
- producer > notes.txt
- producer stdout → host file. An existing file is replaced.
- producer >> notes.txt
- producer stdout → end of host file. Existing contents remain.
- stderr and exit status
- Diagnostics and the shell’s numeric completion status are separate from stdout.
mktemp -d asks the host to create a uniquely named temporary directory and prints its path. Unlike a fixed folder plus mkdir -p, it does not silently reuse an existing lesson folder. Keep the printed assignment: $practice below means “the value saved in this shell variable,” not text to type literally. $(...) runs the command inside and substitutes its printed result; quotes preserve the resulting path as one argument.
Host — Ubuntu Bash; creates one new host directory:
practice=$(mktemp -d "$HOME/android-learning.XXXXXX")
cd "$practice"
pwd
Expected: pwd prints a new path under your home directory, with a unique suffix. If mktemp reports an error or the shell variable is empty, stop; do not run later commands. This is temporary practice data and may be lost during cleanup. The lesson intentionally gives no broad delete/reset command. To resume after closing the terminal, use the exact path pwd printed earlier and inspect it before writing; easiest safe restart is to create another unique directory with the command above. Do not paste a guessed path.
Create a note and display it:
printf 'Android source study\n' > notes.txt
cat notes.txt
Expected output is Android source study. printf writes the text; \n is a newline. > sends output to a file and replaces its contents if the file exists. Our new directory makes the first creation predictable, but if you rerun this command after editing notes.txt, it overwrites your changes. Stop and inspect before using > on a file you care about. >> appends rather than replaces; it also changes data. A pipe | sends one program's output to another program; it does not create a file. Example: printf 'boot\nbuild\n' | sort prints sorted lines. Bash redirections and pipelines
Other useful terms: standard output is a program's ordinary output; standard error commonly carries diagnostics. A process can write to either. Exit status is a small result the shell receives when a program ends; conventionally 0 means success and nonzero means some kind of failure, but the meaning depends on the program. A blank display does not necessarily mean failure. Learn to inspect output and errors before repeating a command.
Git's three places#
- Working tree
The files you edit. git diff compares tracked edits with the index.
- git add → staging area
The selected next snapshot. git diff --staged compares it with HEAD.
- git commit → local history
Records the staged snapshot and metadata; unstaged edits stay outside it.
Git is a distributed version-control system. Its repository is a project plus Git history/metadata. The working tree is files you edit; the staging area (also called the index) is the selection for the next snapshot; a commit records that staged snapshot with metadata. A branch is a movable name for a line of development. A commit is local until you deliberately share it with a remote. Pro Git: What is Git?
Initialize a repo inside the unique practice directory. git init creates a .git metadata directory; the commands below do not download Android or contact a server. The configured name/email are commit author labels, not a GitHub login, password, or authentication token. A shared commit carries those labels. This lesson uses an example .invalid email so you need not expose a personal address. These --local settings apply only to this repository.
git init
git config --local user.name "Android Learner"
git config --local user.email "learner@example.invalid"
git status
Expected: Git reports an initialized repository (initial branch name varies); status reports no commits yet and lists notes.txt as untracked because we created it just above. Exact wording varies with Git version. If Git asks for identity at commit time, stop and set the two local practice values above; do not enter a password or token. If you are not in the directory created above, do not initialize a repository in a folder containing unrelated work.
Now create a file and predict status before running each command:
git status
git diff
git add notes.txt
git status
git diff --staged
git commit -m "Add study note"
git status
git log --oneline
Expected states: status calls notes.txt untracked; ordinary git diff compares the working tree with the index, so it is empty because Git does not show untracked file contents there; after git add, status says the file is staged and git diff --staged shows its line; after commit, status says working tree clean and log shows one commit. Git may print branch-name hints. git add stages current contents; it does not upload. git commit records a local snapshot. Inspect staged changes before committing. Git status · Git add · Git commit
Append a line, inspect, then stage it:
printf 'Kernel notes start here\n' >> notes.txt
git diff
git add notes.txt
git diff --staged
The first diff shows an unstaged addition; after git add, it appears in the staged diff. If an expected state differs, stop and read git status; don't run reset/clean commands to make the screen match. Git commits represent snapshots conceptually; Git reuses stored content internally. Hashes identify content/metadata but do not prove truth, safety, or authorship. Git is not a backup: local history can be lost with its disk. Do not commit passwords, keys, tokens, or personal device data. Deleting a secret later may leave it in history. Avoid git reset --hard and git clean -fd; these can discard work. Pro Git: snapshots and integrity
Practice#
Context: host filesystem and local Git only; no Android device changes and no network publication. In your unique directory, run the Git sequence above one command at a time. Before each git status, write down whether the file should be untracked, staged, or committed. Expected output is described next to the sequence; the exact branch hint and status wording vary. If git init says the directory is already a repository, stop and verify pwd and git status; do not nest repos or delete .git. If identity is missing, configure the practice-only local labels. If you accidentally wrote in the wrong directory, stop before staging; Git is not a tool for guessing which data is safe.
Knowledge check#
- After creating
notes.txtbut beforegit add, why cangit diffbe empty whilegit statuslists a file? - You rerun the
>command after editing notes. What may happen, and what safer action should you take? - Does
git config user.emaillog you into a hosting site? What may happen to that value?
Answers#
- Git reports untracked files in status but ordinary diff compares tracked working-tree content to the index; the new file is not staged yet.
>replaces the file. Inspect first; in this new lab, creating a fresh unique directory is safer than overwriting or broadly deleting. Use>>only if appending is intended.- No. It is commit attribution metadata, not authentication. It is recorded in commits and may be shared if those commits are pushed.
Checkpoint#
Artifact: a private note containing the three predicted status states and the final git log --oneline line; do not publish local paths or personal identity. Ready: you can explain working tree vs staged vs committed and why git add is not upload. Revise: if state/output differs, inspect with git status and revisit “Git's three places”; don't use destructive repair commands. Not yet evidenced: you can only follow a sequence, not predict it; repeat in a newly created practice directory. Then continue to Linux files and processes.
Sources#
- Pro Git, “What is Git?” — snapshots, local operations, integrity, and file states.
- Git status, Git add, Git commit, Git config — official command references and configuration scope.
- Git init and Git diff — repository creation (
.gitdirectory) and working-tree-versus-index comparison. - Bash manual: redirections — output redirection and append behavior.
- AOSP build overview — context for why later platform builds require separate planning and resources.
Next: Linux files and processes.