Collaborative App Development with GitHub

Mohamad's interest is in Programming (Mobile, Web, Database and Machine Learning). He is studying at the Center For Artificial Intelligence Technology (CAIT), Universiti Kebangsaan Malaysia (UKM).
This tutorial guides you through creating a PHP login system while emphasizing the importance of using GitHub for version control and collaborative development. You’ll learn how to set up your project, manage branches, and work seamlessly with a collaborator, all while leveraging the powerful features of Git and GitHub to enhance your workflow.
Prerequisites
GitHub Account: Ensure you have an account set up.
Replit Account: Sign up on Replit (you can use your GitHub account).
Collaborator: A second email for a friend or a willing collaborator.
Part 1: Project Setup on Replit & First Commit
Goal:
Create a new PHP Project, build a light-themed login page, and connect it to GitHub.
Step 1: Create a New PHP Project
Log in to Replit:
- Go to Replit.com and log in to your account.
Create a New Project:
Use "PHP Web" Framework.
Name your Project
phplogin.Click the "Create" button to create your new project.
Step 2: Initialize Git in the Shell
Open the Shell:
- In the Replit interface, locate the "Shell" tab on the right side of the screen (next to the Console tab).
Run Git Commands:
- Enter the following commands to configure Git and initialize your repository:
bash
# Configure Git with your name and email (replace with your details)
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
# Initialize a new Git repository in the Repl
git init
# Create a new branch named 'main'
git checkout -b main
Step 3: Create the Light Theme Login Page
Open
index.php:- In the left pane, find and click on
index.phpto open it.
- In the left pane, find and click on
Replace the Contents:
- Clear the existing content and replace it with the following light theme code:
php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login (Light Theme)</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body { padding: 50px; background-color: #f8f9fa; }
.login-container { max-width: 400px; margin: auto; }
</style>
</head>
<body>
<div class="login-container">
<h2 class="text-center mb-4 text-primary">Please Sign In (Light)</h2>
<form>
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" placeholder="name@example.com" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" placeholder="Password" required>
</div>
<div class="mb-3 form-check">
<input type="checkbox" class="form-check-input" id="remember">
<label class="form-check-label" for="remember">Remember me</label>
</div>
<button type="submit" class="btn btn-primary w-100">Login</button>
</form>
</div>
</body>
</html>
Run the Repl:
- Click the "Run" button at the top of Replit. You should see your light-themed login page displayed in the output pane.
Step 4: Make Your First Commit
Stage and Commit Changes:
- Go back to the Shell and run the following commands:
bash
# Stage all files in the current directory
git add .
# Commit the changes with a descriptive message
git commit -m "feat: add light theme login page"
Step 5: Create a Repository on GitHub and Push from Replit
Create a New Repository:
Go to GitHub and log in.
Click "+ > New repository".
Set the repository name to
phplogin.Set it to Public and do not initialize with a README file.
Click "Create repository".
Copy the Repository URL:
- After creating the repository, copy the HTTPS URL (e.g.,
https://github.com/YOUR_USERNAME/phplogin.git).
- After creating the repository, copy the HTTPS URL (e.g.,
Link and Push to GitHub:
- Back in your Replit Shell, run the following commands to link and push your code:
bash
# Link your Replit to the GitHub repository
git remote add origin https://github.com/YOUR_USERNAME/phplogin.git
# Rename the branch to 'main' and push your code
git branch -M main
git push -u origin main
- If this is your first time using Replit and GitHub, you will be prompted for your GitHub authentication.
Obtaining a Personal Access Token (PAT)
Generate a PAT:Go to GitHub >Settings>Developer settings>Personal access tokens.ClickGenerate new token.Give it"repo"permissions and copy the token.Use this token as your password in the Shell.
Verify the Push:Refresh your GitHub page. Your code should now be online!
Part 2: Creating the Dark Theme on a New Branch
Step 1: Create and Switch to a New Branch
Create a New Branch:
- In the Shell, run the command:
bash
git checkout -b darktheme
Step 2: Modify index.php for Dark Theme
Update
index.php:- Replace the contents of
index.phpwith the dark theme code:
- Replace the contents of
php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login (Dark Theme)</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body { padding: 50px; background-color: #343a40; color: white; }
.login-container { max-width: 400px; margin: auto; }
.form-label { color: white; }
</style>
</head>
<body>
<div class="login-container">
<h2 class="text-center mb-4">Please Sign In (Dark)</h2>
<form>
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" placeholder="name@example.com" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" placeholder="Password" required>
</div>
<div class="mb-3 form-check">
<input type="checkbox" class="form-check-input" id="remember">
<label class="form-check-label" for="remember">Remember me</label>
</div>
<button type="submit" class="btn btn-light w-100">Login</button>
</form>
</div>
</body>
</html>
Run the Repl:
- Click the "Run" button to see the dark-themed login page.
Step 3: Commit and Push the New Branch
Stage and Commit Changes:
- Back in the Shell, run:
bash
git add index.php
git commit -m "feat: redesign for dark theme"
git push -u origin darktheme
- If prompted, enter your GitHub username and PAT again.
Part 3: Collaborating with a Friend via Replit
Step 1: Add a Collaborator on GitHub
Add Collaborator:
Go to your
phploginrepository on GitHub.Click Settings > Collaborators > Add people.
Enter your friend’s email (e.g.,
friend@gmail.com) and click Add collaborator.
Step 2: Friend Accepts Invitation and Forks the Project
Friend Logs In:
- Your friend logs into their Replit account.
Fork the Repository:
They go to your repository URL on GitHub:
https://github.com/YOUR_USERNAME/phplogin.They click the "Fork" button in the top-right corner to create a copy in their own account.
Import Forked Repository in Replit:
Back on Replit, your friend clicks "+ Create Repl" and selects "Import from GitHub".
They paste the URL of their new fork (e.g.,
https://github.com/FRIENDS_USERNAME/phplogin) and click "Import from GitHub".
Step 3: Friend Creates Their Mobile Theme Branch
Open the Shell:
- In their Repl, your friend opens the Shell.
Get Latest from Main Branch:
- Run the following commands:
bash
# Switch to the main branch
git checkout main
# Pull the latest changes from the main branch
git pull origin main
# Create and switch to a new branch for mobile theme
git checkout -b mobile-theme
Step 4: Friend Makes Mobile Changes
Update
index.phpfor Mobile:- Your friend modifies
index.phpto create a mobile-optimized version. Here’s an example:
- Your friend modifies
php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login (Mobile Theme)</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body { padding: 20px; background-color: #f8f9fa; }
.login-container { max-width: 100%; margin: auto; }
</style>
</head>
<body>
<div class="login-container">
<h2 class="text-center mb-4">Please Sign In (Mobile)</h2>
<form>
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" placeholder="name@example.com" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" placeholder="Password" required>
</div>
<div class="mb-3 form-check">
<input type="checkbox" class="form-check-input" id="remember">
<label class="form-check-label" for="remember">Remember me</label>
</div>
<button type="submit" class="btn btn-primary w-100">Login</button>
</form>
</div>
</body>
</html>
Run the Repl:
- They can click the "Run" button to test their changes.
Step 5: Friend Pushes Their Branch and Initiates a PR
Stage and Commit Changes:
- In the Shell, your friend runs:
bash
git add index.php
git commit -m "feat: optimize layout for mobile devices"
git push -u origin mobile-theme
Create a Pull Request:
Your friend goes to their forked repository on GitHub. They will see a banner prompting them to "Compare & pull request" for their new
mobile-themebranch.When creating the pull request, ensure:
Base repository:
YOUR_USERNAME/phploginBase branch:
mainHead repository:
FRIENDS_USERNAME/phploginHead branch:
mobile-theme
This sends the pull request from their fork to your original repository.