Stop losing working code, struggling with project changes, and wondering how developers collaborate. Learn Git, GitHub, branching, commits, pull requests, and professional version control through practical examples.
Have You Ever Changed Your Code and Wished You Could Go Back?
Imagine you’ve spent several hours building a JavaScript application.
Everything works.
Your buttons respond correctly. Your forms validate user input. Your layout looks great on mobile devices.
Then you decide to improve the application.
You ask AI to refactor a few functions, update the CSS, and add another feature.
Suddenly, something breaks.
The original functionality no longer works.
You try to undo the changes, but you’ve already modified several files.
Now you’re searching through previous code, trying to remember what worked before.
Sound familiar?
This is exactly the kind of problem that version control helps solve.
Git allows you to track changes, preserve working versions, experiment safely, and understand how your projects evolve.
And GitHub makes it easier to store repositories remotely, share code, collaborate with others, and manage development workflows.
These aren’t just tools for professional software engineers.
They’re valuable for anyone creating websites, JavaScript applications, Python projects, Google Apps Script tools, or AI-generated software.
In this guide, we’ll explore Git and GitHub from the beginning, practice essential commands, understand branching and merging, and build a complete version control workflow.
We’ll also introduce the Git & GitHub Studio, a DiscoveryVIP learning resource for developing practical version control skills.
Explore the Git & GitHub Studio:
1. What Is Version Control, and Why Does It Matter?
Version control is a system for tracking changes to files over time.
It allows developers to record meaningful versions of their projects and return to earlier states when necessary.
Without version control, projects often become collections of confusing file names:
website-final.html
website-final-new.html
website-final-fixed.html
website-final-v2.html
website-final-v2-really-final.html
This approach quickly becomes difficult to manage.
Which file is correct?
What changed between versions?
Why was something modified?
Which version contains the working feature?
Git provides a structured solution.
Instead of creating separate copies of every file, Git records snapshots of a project’s tracked content through commits.
Each commit becomes part of the project’s history.
For example:
Commit 1: Create website structure
Commit 2: Add responsive navigation
Commit 3: Implement contact form
Commit 4: Fix mobile layout
Commit 5: Add form validation
You can inspect these changes, compare versions, and restore earlier content when needed.
Git vs. GitHub: What’s the Difference?
Although they’re closely related, Git and GitHub are not the same thing.
Git is a distributed version control system.
It runs on your computer and manages your repository history.
GitHub is an online platform that hosts Git repositories and provides collaboration tools.
GitHub adds features such as pull requests, issues, code reviews, project management, and automated workflows.
An important distinction:
You can use Git without GitHub.
You can create repositories, make commits, inspect history, and manage branches entirely on your local computer.
GitHub becomes useful when you want remote storage, sharing, or collaboration.
2. Understand the Three Main Areas of Git
One of the most important concepts for beginners is understanding how Git organizes changes.
There are three main areas to know.
Working Directory
This is where you edit your project files.
For example:
my-website/
index.html
style.css
script.js
When you modify script.js, the working directory contains those changes.
Staging Area
The staging area lets you select which changes will be included in your next commit.
Think of it as preparing a package of changes.
You might modify three files but decide to commit only two.
Repository History
When you create a commit, Git records a snapshot of the staged changes in the repository’s history.
A simplified workflow is:
Edit Files → Stage Changes → Commit Snapshot
Let’s see how that works.
3. Create Your First Git Repository
First, install Git from its official website:
After installation, open your terminal and check that Git is available.
git --version
Next, create a project folder.
mkdir my-first-git-project
cd my-first-git-project
Initialize a repository:
git init
Git creates a hidden .git directory containing the information it needs to manage the repository.
Now configure your author identity if you haven’t already.
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Replace the example values with your own.
These settings identify the author associated with your commits.
Create Your First File
Create a file named index.html.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My First Git Project</title>
</head>
<body>
<h1>Hello Git!</h1>
<p>My first version-controlled website.</p>
</body>
</html>
Now check the repository status.
git status
Git should show that index.html is untracked.
This means Git sees the file but hasn’t included it in a commit.
Stage the file:
git add index.html
Now create your first commit.
git commit -m "Create initial website"
Congratulations!
You’ve created a version-controlled project.
What Did That Commit Do?
Git recorded the staged content as a new snapshot.
You can inspect the commit history using:
git log --oneline
The output will contain a short commit identifier and your message.
For example:
a8c31f2 Create initial website
Your commit identifier will be different.
This is the beginning of your project’s history.
4. Track Changes and Understand What Git Sees
Now modify your HTML file.
Add a button:
<button id="welcomeBtn">
Click Me
</button>
Add some JavaScript:
<script>
document
.querySelector("#welcomeBtn")
.addEventListener("click", () => {
alert("Welcome to Git!");
});
</script>
Save the file.
Then run:
git status
Git will indicate that the tracked file has been modified.
To see the changes:
git diff
This command displays the differences between your working directory and the staged version of the file.
Lines beginning with + represent additions.
Lines beginning with - represent removals.
Stage and Commit the New Feature
git add index.html
git commit -m "Add interactive welcome button"
Now inspect the history.
git log --oneline
You should see two commits.
Each commit represents a meaningful point in your project’s development.
Why Commit Messages Matter
Compare these messages:
update
changes
fix
stuff
With these:
Add mobile navigation menu
Fix contact form validation
Improve dashboard loading feedback
Refactor product filtering logic
Good commit messages explain the purpose of a change.
This becomes especially useful when reviewing code months later or collaborating with other developers.
A commit message should help someone understand what changed without requiring them to inspect every line of code.
5. Learn Branching: Experiment Without Breaking Your Main Project
Branches are one of Git’s most powerful features.
A branch provides a separate line of development.
Imagine your website is working correctly.
You want to experiment with a new navigation system.
Instead of changing your main branch immediately, you can create a feature branch.
git switch -c feature/mobile-navigation
This creates a new branch and switches to it.
Now you can modify your project.
Add new HTML.
Change your CSS.
Update JavaScript interactions.
Make commits as you work.
git add .
git commit -m "Build responsive navigation"
Your changes are recorded on the feature branch.
The main branch remains at its previous commit until you integrate the work.
Switch Back to Main
git switch main
This example assumes your primary branch is named main.
If your repository uses a different name, substitute that name.
Merge the Feature
When the feature is tested and ready:
git merge feature/mobile-navigation
Git integrates the feature branch into the current branch.
If the histories permit, Git may perform a fast-forward merge.
Otherwise, Git may create a merge commit.
Why Branching Is Valuable
Branches let you:
- Experiment with new features
- Test AI-generated changes
- Fix bugs independently
- Collaborate without immediately modifying the main branch
- Review changes before integration
This is particularly useful when working with AI coding assistants.
Before asking AI to make a significant change, create a branch.
That gives you a clear point of separation between your stable project and the experiment.
6. What Happens When Git Finds a Merge Conflict?
A merge conflict occurs when Git cannot automatically reconcile competing changes.
For example, imagine two developers modify the same line of a JavaScript file.
Developer A changes:
const message = "Welcome!";
Developer B changes it to:
const message = "Hello there!";
When Git attempts to combine the branches, it may require human input.
A conflicted file can contain markers like:
<<<<<<< HEAD
const message = "Welcome!";
=======
const message = "Hello there!";
>>>>>>> feature/greeting
These markers identify the conflicting content.
You must decide which version to keep or how to combine them.
For example:
const message = "Welcome to our website!";
After resolving the conflict, stage the corrected file.
git add script.js
Then complete the merge using the appropriate Git command for the merge in progress, commonly:
git commit
A Better Way to Approach Conflicts
Don’t randomly delete conflict markers and hope everything works.
Instead:
- Understand what each version was trying to accomplish.
- Decide which behavior should remain.
- Edit the file to produce the correct combined result.
- Run the application and test the affected functionality.
- Complete the merge.
Merge conflicts are not necessarily errors.
They are situations where Git needs you to make a decision.
7. GitHub: Take Your Repository Online
Once you’ve learned local Git, the next step is understanding remote repositories.
GitHub allows you to host a Git repository online.
This makes it easier to share code, collaborate, and access your project from multiple computers.
Visit:
Create an account if you don’t already have one.
Then create a new repository.
For this example, name it:
my-first-git-project
If you already have a local repository, create the GitHub repository without initializing it with another README or Git history.
Connect Your Local Repository
Use the repository URL provided by GitHub.
For an HTTPS remote, the command looks like this:
git remote add origin https://github.com/USERNAME/my-first-git-project.git
Replace USERNAME with your GitHub username.
If your primary branch should be named main, you can rename it:
git branch -M main
Push your commits:
git push -u origin main
You may be asked to authenticate.
GitHub supports authentication methods such as Git Credential Manager, GitHub CLI, personal access tokens, and SSH keys.
Your GitHub account password is not used directly for Git operations over HTTPS.
What Does Push Mean?
git push sends local commits to a remote repository.
What Does Pull Mean?
git pull fetches changes from a remote repository and integrates them into your current branch.
What Does Clone Mean?
git clone creates a local copy of an existing repository.
git clone https://github.com/USERNAME/my-first-git-project.git
These three operations form an important part of everyday GitHub development.
8. Learn the Professional GitHub Workflow
In many development teams, changes are not pushed directly to the main branch.
Instead, developers use feature branches and pull requests.
A typical workflow looks like this:
Create Issue → Create Branch → Make Changes → Commit → Push → Open Pull Request → Review → Merge
Let’s walk through an example.
Step 1: Define the Feature
Suppose your project needs a dark mode toggle.
Create a GitHub issue describing the expected behavior.
Example:
Feature: Add Dark Mode
Requirements:
- Add a toggle button.
- Switch between light and dark themes.
- Preserve the selected theme.
- Support keyboard interaction.
- Test on mobile devices.
Step 2: Create a Branch
git switch -c feature/dark-mode
Step 3: Implement the Feature
Add the necessary HTML, CSS, and JavaScript.
Step 4: Test the Feature
Verify that the toggle works and the selected theme is preserved.
Step 5: Commit
git add .
git commit -m "Add persistent dark mode toggle"
Step 6: Push the Branch
git push -u origin feature/dark-mode
Step 7: Open a Pull Request
On GitHub, create a pull request proposing to merge your feature branch into the main branch.
Explain what changed and how you tested it.
Step 8: Review and Merge
Review the differences.
Address feedback.
Run tests.
Merge the pull request when the change is ready.
This workflow creates a clear record of why the feature was developed, what changed, and how it was reviewed.
9. Protect Your Projects with .gitignore
Not every file belongs in a Git repository.
Some files are generated automatically.
Others contain private information.
A .gitignore file tells Git which untracked files and folders should normally be ignored.
For a Node.js project, you might use:
node_modules/
.env
.env.local
dist/
coverage/
*.log
.DS_Store
This prevents commonly generated files and local environment configuration files from being added accidentally.
However, .gitignore does not remove files that Git is already tracking.
If a sensitive file has already been committed, simply adding it to .gitignore is not enough.
You must stop tracking the file and, where necessary, remove the secret from repository history.
If an API key or credential is accidentally exposed, revoke or rotate it immediately.
This is especially important for AI projects that use external APIs.
Never commit private API keys, access tokens, or passwords.
10. Undo Changes Safely with Git
One of the biggest advantages of version control is the ability to recover from mistakes.
But Git provides several different recovery commands, and choosing the correct one matters.
Inspect Your Changes
git status
git diff
Start here before attempting recovery.
Restore an Uncommitted File
If you modified a tracked file but haven’t staged the changes:
git restore index.html
This discards the unstaged modifications to that file.
Warning: The discarded changes may be difficult or impossible to recover.
Remove a File from the Staging Area
git restore --staged index.html
This unstages the file without discarding its working-directory changes.
Revert a Commit
If a commit has already been shared, git revert is often the safer option.
git revert COMMIT_HASH
This creates a new commit that reverses the changes introduced by the selected commit, where possible.
It preserves the existing history.
What About git reset?
git reset can move the current branch to another commit and optionally modify the staging area and working directory.
It is powerful but can be destructive.
For example, git reset --hard can discard uncommitted changes.
Beginners should understand its effects before using it.
Practical Rule
For shared history, prefer reverting a change rather than rewriting history without coordinating with collaborators.
11. Git Stash: Temporarily Save Unfinished Work
Sometimes you’re working on a feature when an urgent issue appears.
You need to switch branches, but your current changes aren’t ready to commit.
Git stash can help.
git stash push -m "Work in progress on dashboard"
This saves eligible uncommitted changes and restores the corresponding working files to their recorded state.
You can then switch branches.
git switch main
Later, return to your feature branch and restore the stashed changes.
git stash pop
You can inspect saved stashes using:
git stash list
By default, stash does not include untracked files unless you explicitly request that behavior.
Also remember that applying a stash can produce conflicts.
Stash is useful for temporary work, but it shouldn’t replace a clear commit strategy.
12. Git and AI-Assisted Development: A Workflow Every Developer Should Learn
AI coding tools can generate large amounts of code quickly.
They can also modify files across an entire application.
This creates opportunities for faster development, but it also introduces risks.
Imagine asking AI:
“Refactor my JavaScript application to improve performance.”
The AI might change several functions, rename variables, reorganize files, and update dependencies.
Some improvements may be useful.
Others may introduce bugs.
Without version control, identifying and reversing the problematic changes can become difficult.
A safer approach combines AI with Git.
A Practical AI + Git Workflow
Step 1: Start with a Working Version
Make sure the current application runs correctly.
Commit the stable state.
git add .
git commit -m "Save working dashboard baseline"
Step 2: Create an Experiment Branch
git switch -c experiment/ai-refactor
Step 3: Give AI a Focused Task
Instead of asking for a complete rewrite, request one clearly defined improvement.
For example:
“Refactor the filtering function to improve readability without changing its behavior.”
Step 4: Inspect the Changes
git diff
Look for unexpected modifications.
Step 5: Test the Application
Run existing tests and manually check affected features.
Step 6: Commit Verified Improvements
git add .
git commit -m "Refactor dashboard filtering"
Step 7: Review Before Merging
Compare the feature branch with the stable branch.
Only integrate the work when the results meet your requirements.
This creates a repeatable process:
Plan → Branch → Generate → Review → Test → Commit → Merge
The same workflow applies to AI-generated websites, JavaScript applications, Python tools, and automation projects.
Git gives you the confidence to experiment without losing control of your work.
13. Five Git Commands Every Developer Should Know
You don’t need to memorize every Git command.
Start with the ones you’ll use regularly.
| Command | Purpose |
|---|---|
git status | Check repository changes |
git add | Stage selected changes |
git commit | Record a snapshot |
git log | Inspect commit history |
git diff | Compare changes |
Once you’re comfortable with these, add branching and remote repository commands.
| Command | Purpose |
|---|---|
git switch -c | Create and switch to a branch |
git switch | Change branches |
git merge | Integrate branch history |
git push | Send commits to a remote |
git pull | Fetch and integrate remote changes |
git clone | Copy a repository locally |
git restore | Restore selected file content |
The goal is to understand what each command changes.
Before running a command, ask:
Does it affect my working files?
Does it affect the staging area?
Does it change commit history?
Does it interact with a remote repository?
Understanding these distinctions prevents many common mistakes.
14. Common Git and GitHub Mistakes
Mistake 1: Making One Giant Commit
A commit containing dozens of unrelated changes is difficult to review.
Prefer small, meaningful commits that represent coherent work.
Mistake 2: Writing Unhelpful Commit Messages
Messages such as “update” or “fix stuff” provide little context.
Describe the purpose of the change.
Mistake 3: Working Directly on Main for Every Feature
Feature branches make experimentation and review easier.
Mistake 4: Committing Secrets
Never store private credentials in a repository.
Use environment variables and appropriate secret-management tools.
Mistake 5: Using Destructive Commands Without Understanding Them
Commands such as git reset --hard can discard changes.
Inspect the repository state before using recovery commands.
Mistake 6: Ignoring Merge Conflicts
Conflicts require understanding and testing, not just removing markers.
Mistake 7: Treating GitHub as a Complete Backup System
A remote repository provides valuable redundancy, but it doesn’t automatically replace a comprehensive backup strategy.
Uncommitted work, ignored files, and external project resources may not be included.
Mistake 8: Accepting AI-Generated Changes Without Review
AI can accelerate coding, but developers remain responsible for verifying the result.
15. Use AI as Your Git Learning Coach
Git can feel intimidating because many commands affect files, branches, and history.
AI can help you understand the consequences of commands before executing them.
The key is to ask for explanations and safe procedures rather than blindly copying instructions.
Prompt 1: Git Beginner Tutor
Act as an experienced Git instructor.
Teach me the following Git concept:
[TOPIC]
My experience level:
[BEGINNER / INTERMEDIATE]
Explain:
1. What the concept means
2. Why developers use it
3. Which Git areas it affects
4. A realistic example
5. The relevant commands
6. Common mistakes
7. One hands-on exercise
Ask me to predict what will happen
before revealing the result.
Focus on understanding,
not memorizing commands.
Prompt 2: Git Command Safety Checker
Act as a senior Git developer.
I am considering running this command:
[COMMAND]
My current repository state:
[PASTE GIT STATUS]
My goal:
[DESCRIBE OUTCOME]
Explain:
1. What the command does
2. Which files or history it changes
3. Whether it can discard work
4. A safer alternative, if appropriate
5. How to verify the result
Do not recommend destructive commands
without clearly explaining the risks.
Prompt 3: Merge Conflict Coach
Help me resolve a Git merge conflict.
Here is the conflicted file:
[PASTE CONFLICT]
Explain:
1. What each version represents
2. Why the conflict occurred
3. What decisions I need to make
4. A safe resolution process
5. How to test the result
6. How to complete the merge
Do not assume which version is correct.
Ask questions if the intended
behavior is unclear.
Prompt 4: GitHub Pull Request Reviewer
Act as a professional code reviewer.
Review this proposed change:
[DESCRIBE FEATURE]
Changed files:
[LIST FILES]
Code differences:
[PASTE DIFF]
Evaluate:
- Correctness
- Scope of changes
- Security
- Maintainability
- Testing
- Documentation
Identify the most important issues.
Suggest a clear pull request description
and a practical testing checklist.
Prompt 5: AI Coding Workflow Planner
Help me plan a safe Git workflow
for an AI-assisted coding task.
Project:
[DESCRIBE APPLICATION]
Current working state:
[DESCRIBE]
Requested AI change:
[DESCRIBE]
Provide:
1. Recommended branch name
2. Pre-change verification steps
3. Focused AI implementation prompt
4. Git commands to inspect changes
5. Testing checklist
6. Suggested commit messages
7. Merge criteria
8. Recovery options
Prioritize preserving working code
and making changes easy to review.
These prompts support the development of judgment, not just command execution.
16. A Seven-Day Git & GitHub Learning Challenge
Here’s a practical learning path that builds from your first repository to a collaborative development workflow.
Day 1 — Create Your First Repository
Install Git.
Create a project folder.
Initialize a repository.
Add an HTML file.
Create your first commit.
Challenge: Explain the difference between the working directory, staging area, and repository history.
Day 2 — Track Changes
Modify your project.
Use git status and git diff.
Stage and commit the changes.
Inspect the commit history.
Challenge: Make three meaningful commits with descriptive messages.
Day 3 — Practice Branching
Create a feature branch.
Add a new website feature.
Commit the work.
Switch between branches.
Challenge: Explain why the feature appears on one branch but not the other.
Day 4 — Learn Merging
Merge your feature into the main branch.
Create a controlled merge-conflict exercise in a disposable practice repository.
Resolve the conflict.
Test the result.
Challenge: Explain what Git can merge automatically and when human decisions are needed.
Day 5 — Connect to GitHub
Create a GitHub repository.
Connect your local repository.
Push your commits.
Clone the repository into a separate folder.
Challenge: Explain the difference between local and remote history.
Day 6 — Use Pull Requests
Create a new feature branch.
Push it to GitHub.
Open a pull request.
Review the changes.
Merge the feature.
Challenge: Write a pull request description that explains the feature and how it was tested.
Day 7 — Build with AI and Git
Choose a small JavaScript application.
Commit the working version.
Create a branch.
Use AI to implement one feature.
Review the differences.
Test the application.
Commit and merge the improvement.
Final Challenge: Explain how Git helped you manage the AI-generated changes.
By the end of the week, you’ll have practical experience with the workflows developers use to manage real projects.
17. Applying Vibe Learning to Git and GitHub
Git is a perfect subject for hands-on learning because its behavior becomes clearer through experimentation.
You can read about branches for hours.
But creating two branches, modifying a file, switching between them, and inspecting the results makes the concept much easier to understand.
This connects directly with the principles of Vibe Learning.
A practical learning cycle looks like this:
Explore: Understand a Git concept.
Predict: Decide what a command will change.
Execute: Run the command in a safe practice repository.
Observe: Inspect the repository state.
Explain: Describe why the result occurred.
Apply: Use the same technique in a real project.
For example, before running:
git switch feature/navigation
Ask yourself:
What happens to my working files?
Which branch will become active?
What happens if I have uncommitted changes?
Then test your prediction in a disposable repository.
This is much more effective than memorizing commands without understanding their consequences.
The goal isn’t to know every Git command. It’s to understand how Git manages changes so you can use it confidently.
18. Explore the Git & GitHub Studio
Version control becomes easier when you can experiment, inspect changes, and connect concepts to practical projects.
Start with the fundamentals.
Learn how commits work.
Practice branching.
Experiment with merging and recovery.
Then connect your repository to GitHub and explore collaborative workflows.
The Git & GitHub Studio is a DiscoveryVIP learning resource to explore alongside these practical exercises.
Explore the Git & GitHub Studio:
You can also explore the DiscoveryVIP learning library for additional resources covering JavaScript, web development, AI-assisted coding, debugging, and software engineering.
For more information about project-based learning and AI-assisted skill development, explore:
Final Thoughts: Git Gives You the Freedom to Experiment
Learning Git and GitHub changes how you approach software development.
Instead of worrying about losing working code, you can create meaningful snapshots.
Instead of making every change directly to your main project, you can experiment in branches.
Instead of guessing what changed, you can inspect differences.
Instead of struggling to collaborate, you can use pull requests and code reviews.
And when working with AI-generated code, Git becomes even more valuable.
It provides a clear record of what changed, helps you review the results, and makes it easier to recover when an experiment doesn’t work.
The most important benefit of Git isn’t simply tracking files. It’s giving you the confidence to build, experiment, test, and improve without losing control of your project.
Start with one repository.
Make one commit.
Create one branch.
Test one feature.
Then keep building.
Those small habits form the foundation of professional software development.
About the Author
Laurence Svekis is a Google Developer Expert (Google Workspace), Google Champion, author, developer, and educator who has taught 3 million+ students through online courses and practical learning resources.
He is the creator of Vibe Learning and Vibe Teaching, approaches focused on active learning, practical experimentation, AI-assisted development, and meaningful understanding.
Through DiscoveryVIP.com and VibeLearning.ca, Laurence creates interactive learning tools, educational guides, and hands-on resources covering JavaScript, Google Apps Script, web development, artificial intelligence, automation, and modern software engineering.