Fruitful™
GitHub Developer Handbook and Staff Training Manual
Your A-Z Guide to Version Control and Collaboration
GitHub is a web-based platform that uses Git for version control. It's a powerful tool for developers to collaborate on projects, track changes, and manage their codebases efficiently. Think of it as a central hub where all your project's code lives, and where every change is meticulously recorded.
This manual will guide you through setting up Git and GitHub, understanding fundamental commands, and adopting best practices for a seamless development workflow within the FAA.ZONE Ecosystem.
If you don't already have one, your first step is to create a GitHub account. This account will host your repositories and allow you to interact with other developers' projects.
Git is the distributed version control system that GitHub is built upon. You need to install Git on your local machine to interact with GitHub repositories.
git --version
. If not, install Xcode Command Line Tools:
xcode-select --install
Or use Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install git
sudo apt update
sudo apt install git
After installation, open your terminal (or Git Bash on Windows) and verify Git is installed correctly:
git --version
You need to tell Git who you are so that your commits are correctly attributed.
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
Replace "Your Name"
and "[email protected]"
with your actual name and the email associated with your GitHub account.
SSH keys provide a more secure way to connect to GitHub without typing your username and password every time. It's highly recommended for a smoother workflow.
Open your terminal and run the following command. Replace "[email protected]"
with your GitHub email.
ssh-keygen -t ed25519 -C "[email protected]"
Press Enter for the default file location. You can set a passphrase for extra security, but it's optional.
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
(If you created a different filename, use that instead of id_ed25519
)
pbcopy < ~/.ssh/id_ed25519.pub
cat ~/.ssh/id_ed25519.pub | clip
xclip
or xsel
first:
sudo apt-get install xclip
xclip -sel clip < ~/.ssh/id_ed25519.pub
These are the commands you'll use most frequently. Understanding their purpose is key to effective version control.
git init
: Initialize a New RepositoryThis command creates a new Git repository in the current directory. It's typically done once per project if you're starting from scratch locally.
cd my-new-project/
git init
This creates a hidden .git
directory where Git stores all its tracking information.
git clone
: Copy an Existing RepositoryUse this to get a copy of an existing repository (e.g., from GitHub) onto your local machine. This sets up the remote connection automatically.
git clone <repository-url>
Example: git clone [email protected]:your-org/your-repo.git
(using SSH) or git clone https://github.com/your-org/your-repo.git
(using HTTPS).
git status
: Check Your Working Directory StatusThis command shows you which files have been modified, staged, or are untracked. It's your quick health check for your local repository.
git status
You'll see files in red (modified/untracked) and green (staged for commit).
git add
: Stage Changes for CommitBefore you commit changes, you need to "stage" them. This tells Git which specific changes you want to include in your next commit.
git add <file-name> # Stage a specific file
git add . # Stage all changes in the current directory
git add -u # Stage changes to tracked files only
Always run git status
after git add
to confirm files are staged.
git commit
: Record Changes to the RepositoryA commit is a snapshot of your repository at a specific point in time. Each commit has a unique ID and a commit message explaining the changes.
git commit -m "Your descriptive commit message"
A good commit message concisely describes *what* changed and *why*. Avoid vague messages like "Fixed bugs".
For multi-line messages, omit -m
and Git will open your default text editor.
git log
: View Commit HistoryShows a chronological list of commits in the current branch. Useful for understanding project history.
git log # Full log
git log --oneline # Concise one-line view
git log --graph --oneline --all # Visualizes branches and merges
git branch
: Manage BranchesBranches allow you to work on new features or bug fixes in isolation without affecting the main codebase.
git branch # List all local branches
git branch <new-branch-name> # Create a new branch
git branch -d <branch-to-delete> # Delete a local branch (after merging)
git checkout
: Switch Branches or Restore FilesMoves your working directory to a different branch, or retrieves a specific file from a commit.
git checkout <branch-name> # Switch to an existing branch
git checkout -b <new-branch-name> # Create and switch to a new branch
git checkout <commit-hash> -- <file-path> # Restore a file from a specific commit
git pull
: Fetch and Integrate Remote ChangesUpdates your local branch with the latest changes from the remote repository. It's a combination of git fetch
(downloads changes) and git merge
(integrates them).
git pull origin <branch-name>
Often simplified to git pull
if your branch is set to track a remote branch.
Always git pull
before starting work and before pushing to ensure you're on the latest version and to minimize merge conflicts.
git push
: Upload Local Commits to RemoteSends your committed changes from your local branch to the remote repository on GitHub.
git push origin <branch-name>
The first time you push a new branch, you might need to set the upstream: git push -u origin <branch-name>
.
Ensure your changes are committed and your local branch is up-to-date with the remote (via git pull
) before pushing.
git merge
: Integrate Changes from One Branch into AnotherCombines the history of two (or more) development lines together. Commonly used to bring changes from a feature branch into main
or develop
.
# First, switch to the branch you want to merge *into*
git checkout main
# Then, merge the feature branch into the current branch
git merge feature-branch-name
Git will attempt to merge automatically. If there are conflicts, you'll need to resolve them manually.
Beyond basic Git commands, GitHub introduces powerful features for team collaboration.
faa-zone-api-service
)..gitignore
file (select a template like "Node" or "Python" based on your project).We will primarily use a "GitHub Flow" inspired strategy for feature development:
main
branch: This branch should always be deployable. Only merged via Pull Requests after review.main
.
git checkout main
git pull origin main
git checkout -b feature/your-awesome-feature
Pull Requests are how you propose changes, discuss them, and get them reviewed before merging into a main branch.
git add .
git commit -m "feat: implement user authentication"
git push -u origin feature/your-awesome-feature
After pushing, GitHub will usually provide a direct link in the terminal to create a PR. Alternatively, go to your repository on GitHub, navigate to the "Pull requests" tab, and click "New pull request".
Select your feature branch as the "compare" branch and main
as the "base" branch.
Explain what the PR does, why it's needed, and any relevant context (e.g., linking to an issue).
main
branch.git branch -d feature/your-awesome-feature
Merge conflicts occur when Git cannot automatically reconcile changes between two branches (e.g., two people modified the same line of code).
git pull
or git merge
.
Auto-merging conflicting-file.js
CONFLICT (content): Merge conflict in conflicting-file.js
Automatic merge failed; fix conflicts and then commit the result.
<<<<<<<
, =======
, and >>>>>>>
.
<<<<<<< HEAD
console.log('My new feature');
=======
console.log('Existing functionality');
>>>>>>> feature/another-branch
HEAD
represents your current branch's version, and the section after =======
is the incoming change.
git add conflicting-file.js
git commit -m "Merge branch 'feature/another-branch' into main (resolved conflicts)"
Git will often pre-populate a merge commit message; you can usually save and close it.
GitHub's "Issues" tab is for tracking tasks, bugs, and feature requests. "Projects" (or "Project boards") help organize these issues into Kanban-style boards for workflow management.
GitHub Pages allows you to host static websites directly from your GitHub repositories.
main
or gh-pages
) and the folder (e.g., /root
or /docs
).yourusername.github.io/your-repo-name
.GitHub Actions is a CI/CD (Continuous Integration/Continuous Deployment) platform built into GitHub. It allows you to automate workflows directly in your repository (e.g., running tests, building code, deploying applications) on every push or pull request.
Actions are defined in YAML files (.github/workflows/*.yml
) and trigger based on events.
Example workflow for running tests:
# .github/workflows/ci.yml
name: CI
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
Fruitful™ represents a critical initiative within the FAA.ZONE Ecosystem. It is designed to foster innovation and generate valuable outcomes through a collaborative, structured approach. This section outlines its purpose and how it integrates with our GitHub workflows.
Fruitful™ aims to be the engine for our creative and problem-solving processes. It embodies our commitment to:
The "Fruitful™" logo represents growth, abundance, and the successful cultivation of ideas within our ecosystem, signifying the fertile ground we provide for projects to flourish from conception to completion.
Fruitful™ is not just a concept; it's integrated into our daily development practices, primarily through our GitHub workflow. All projects under the Fruitful™ umbrella will adhere to the following:
fruitful-project-name
).fruitful-feature
, fruitful-bug
, fruitful-enhancement
) will be consistently applied for easy identification, filtering, and reporting.By rigorously applying these GitHub-centric practices, Fruitful™ ensures that our innovations are not only well-conceived but also robustly developed and seamlessly integrated into the FAA.ZONE Ecosystem.
Adhering to these practices will make your team more efficient and your codebase more maintainable.
feat: Add user profile page
This commit introduces a new user profile page with editable fields
for name, email, and password. It also includes validation for
form inputs and integration with the backend API for data retrieval.
Resolves #123.
git pull
from your base branch (e.g., main
) before starting work and before creating a Pull Request to minimize merge conflicts..gitignore
: Prevent unwanted files (e.g., node_modules
, .env
, build artifacts) from being committed by adding them to your .gitignore
file.main
(and any other critical branches) to require PRs, passing status checks, and approvals.# Add upstream remote if not already added
git remote add upstream https://github.com/original-org/original-repo.git
# Fetch from upstream
git fetch upstream
# Checkout your local main branch
git checkout main
# Merge upstream changes into your local main
git merge upstream/main
# Push changes to your fork (if applicable)
git push origin main
Here are some common problems you might encounter and how to resolve them.
If you encounter CONFLICT (content): Merge conflict...
, refer back to section 4.4. The key is to manually edit the file to resolve the conflicting lines, then git add
and git commit
.
This means your local branch is behind the remote branch. Someone else has pushed changes that you don't have locally.
git pull origin <your-branch-name>
# Resolve any conflicts if they arise
git push origin <your-branch-name>
GitHub recommends using PATs instead of passwords for HTTPS. Generate a new PAT from GitHub Settings -> Developer settings -> Personal access tokens. Give it appropriate scopes (e.g., repo
). When prompted for a password, use the PAT.
Use with extreme caution, especially on shared branches.
git reset HEAD~1 # Unstages the last commit, keeps changes
git reset --hard HEAD~1 # Discards the last commit and its changes (DANGEROUS!)
git revert <commit-hash> # Creates a new commit that undoes the specified commit (safer)
git reset --hard <commit-hash-before-undesired-commit>
git push --force origin <branch-name> # DANGEROUS! Overwrites remote history. ONLY use if you are 100% sure and others haven't pulled your changes.
This section provides a comprehensive list of Git commands beyond the daily essentials, offering more powerful ways to manage your codebase and history. Each command includes a brief description of its primary function.
git switch <branch-name>
: A newer, safer alternative to `git checkout` for switching branches.git switch -c <new-branch-name>
: Creates and switches to a new branch.git branch -m <old-name> <new-name>
: Renames a local branch.git merge --abort
: Stops a merge process if conflicts are too complex or you change your mind.git rebase <base-branch>
: Rewrites commit history by moving a series of commits to a new base. Use with caution on shared branches.git rebase --continue
: Continues a rebase after resolving conflicts.git rebase --abort
: Aborts an ongoing rebase operation.git cherry-pick <commit-hash>
: Applies changes from a specific commit from one branch onto another.git stash
: Temporarily saves changes that are not ready to be committed, cleaning up the working directory.git stash pop
: Applies the most recently stashed changes and removes them from the stash list.git tag <tag-name>
: Creates a lightweight tag (e.g., for release versions).git tag -a <tag-name> -m "Message"
: Creates an annotated tag (recommended for releases, includes metadata).git diff
: Shows changes between the working tree and the index, or between two commits/branches.git diff --staged
: Shows changes between the index and the last commit.git blame <file-name>
: Shows what revision and author last modified each line of a file.git reflog
: Displays a log of all actions performed in your local repository, including checkouts and resets. Useful for recovering lost commits.git shortlog
: Summarizes `git log` output, grouped by author.git show <commit-hash>
: Displays metadata and content changes of a single commit, tag, or tree object.git remote -v
: Lists all configured remote repositories and their URLs.git remote add <name> <url>
: Adds a new remote repository.git remote rm <name>
: Removes a remote.git fetch
: Downloads objects and refs from another repository (e.g., origin), but does not merge them.git config --list
: Lists all Git configurations.git config --global core.editor "code --wait"
: Sets VS Code as the default Git editor (example).This list is a starting point; Git has many more commands and options. Use git help <command>
for detailed documentation on any specific command (e.g., git help rebase
).
While the command line provides full control over Git, desktop applications offer a visual interface that can simplify many common operations, especially for those who prefer graphical tools. Popular Git desktop apps include GitHub Desktop, GitKraken, Sourcetree, and VS Code's integrated Git features.
The core concepts and workflows (cloning, committing, pushing, pulling, branching, creating Pull Requests) remain the same, but the method of execution changes from typing commands to clicking buttons and interacting with visual elements.
Typically found under "File" or "Repository" menu as "Clone Repository". You'll provide the repository URL (HTTPS or SSH) and choose a local directory.
Equivalent to: git clone <repository-url>
Desktop apps usually show a list of modified files. You can select individual files or all changed files to stage them for the next commit. This might involve checking a box next to the file name or dragging it to a "Staged Changes" area.
Equivalent to: git add <file-name>
or git add .
After staging, there's usually a dedicated area to write your commit message (subject and optional description) and a "Commit" button. The app will automatically include your configured Git user name/email.
Equivalent to: git commit -m "Your message"
A "Pull" or "Fetch origin" button (often with a down arrow icon) will retrieve and integrate changes from the remote repository to your current local branch. It's crucial to do this frequently.
Equivalent to: git pull
A "Push" or "Push origin" button (often with an up arrow icon) sends your committed local changes to the remote repository.
Equivalent to: git push
Most apps have a branch selector dropdown where you can see existing branches and an option to "New Branch" or "Create Branch". Switching is as simple as selecting a different branch from the list.
Equivalent to: git branch <new-branch>
and git checkout <branch-name>
(or git switch
)
After pushing a new branch to GitHub, many desktop apps will provide a direct link or a button like "Create Pull Request" that takes you directly to GitHub's PR creation page, pre-filling much of the information.
Equivalent to: Pushing a new branch and then navigating to GitHub.com to create the PR.
When a pull or merge results in conflicts, desktop apps often highlight the conflicting files and provide a visual interface to help you manually resolve them, showing "incoming" and "current" changes side-by-side or inline. After editing, you'll mark the conflict as resolved within the app.
Equivalent to: Manual file editing, then git add
and git commit
for the merge.
While the visual tools simplify the *execution*, understanding the underlying Git concepts from the command-line sections (e.g., staging area, commit history, branching) will make you a more effective user of any Git desktop application. They are two different interfaces to the same powerful system.
This handbook provides a comprehensive foundation for using Git and GitHub effectively within the FAA.ZONE Ecosystem. Mastering these tools is crucial for our collaborative success and the efficient management of our codebase.
Remember to practice regularly, utilize GitHub's documentation for deeper dives, and always communicate changes through Pull Requests. Your consistent adherence to these guidelines ensures a smooth and productive development experience for everyone.
Should you encounter issues not covered here, consult official Git and GitHub documentation, or refer to common online resources. This manual is designed to empower you to resolve issues independently and contribute confidently.