๐งญ Topic: Java & Git
Quick Overview :
This topic covers Git version control fundamentals alongside Java development, teaching you how to manage your code professionally using Git workflows, repositories, and collaboration tools.
๐ Covered in This Topic
Introduction to Git
- What is Git (distributed version control system)
- Why developers use Git:
- Track changes in code
- Manage different versions of a project
- Works both locally and in teams
- Helps organize your coding progress
- Lets you undo mistakes and view history
- What is a Repository: A folder where Git tracks your files
Installing & Configuring Git
- Download and install Git from internal or public sources
- Choose your default editor (VS Code, Vim, Notepadโฆ)
- Setting global identity:
git config --global user.name "Your Name" git config --global user.email "your-email@example.com" - Setting local identity for specific projects:
git config --local user.name "Work Name" git config --local user.email "your-email@company.com"
Basic Git Workflow
- Working Directory โ Staging Area โ Repository
- Three-step process:
- Make changes to files
git add- stage changesgit commit- save snapshot
Starting a Project from Scratch
- git init:
- Transforms a regular directory into a Git-managed repository
- Creates a hidden
.gitfolder storing the projectโs entire history
- git status:
- Displays the state of the working directory
- Shows if files are: Untracked (new), Modified (changed), Staged (ready to commit), Clean (no pending changes)
- git add
<file-name>:- Moves changes from working directory to Staging Area
- Prepares files for the upcoming commit (snapshot)
- git commit -m โYour descriptive messageโ:
- Permanently records changes in the repositoryโs history
- Takes a โsnapshotโ of your project at this specific point in time
- git log:
- Views the projectโs commit history
- git restore
<file>:- Discards changes in working directory
Creating a Local Repository
- Creating project folder
- Initializing Git repository:
git init - Renaming default branch:
git branch -m master main - Creating development branch:
git checkout -b develop - Adding and committing files:
git add . git commit -m "Initial commit on develop branch" - Merging into main:
git checkout main git merge develop
Working with an Existing Project
- git clone
<repository-url>:- Creates a local copy of a remote repository
- Downloads project files and the full commit history
- git branch
<branch-name>:- Creates a new branch for development
- Allows working on a feature or fix without affecting the main branch
- git checkout
<branch-name>:- Moves between branches
- Updates working directory to match the selected branch
- git merge feature-x:
- Combines changes from feature-x branch into current branch
- Integrates commits from feature-x into your current branch
Online Git Repositories
- Creating account on Git.Meshcomp
- Following mentors
- Creating new repositories
- Repository configuration:
- Public/Private
- Add description
- Donโt initialize with .gitignore, License, README
- Default branch: main
Remote Repository Management
- git remote:
- Views configured remote repositories
- Displays list of remote repositories connected to your local repository
- Remote servers allow you to push and pull code from external servers
- Adding remote:
git remote add origin http://git.meshcomp.ir/USERNAME/REPOSITORY.git - git push origin
<branch-name>:- Uploads local commits to a remote repository
- Sends commits from your local branch to the remote repository called origin
- Pushing to remote:
git push -u origin main - Forking repositories
- Cloning repositories:
git clone https://git.meshcomp.ir/YOUR_USERNAME/repository-name.git
Git Workflow for Assignments
- Fork the repository
- Clone your forked repository
- Add mentor as collaborator (Settings โ Collaborators)
- Set up Maven mirrors for restricted internet:
- Configure
settings.xmlin~/.m2/directory - Use mirror:
https://maven.devneeds.ir/
- Configure
- Create develop branch:
git checkout -b develop - Implement solutions in Java
- Run unit tests (JUnit)
- Commit work:
git add . git commit -m "Implement method" - Push to remote:
git push origin develop - Create Pull Request to your own repository:
- base:
mainโ compare:develop
- base:
- Share PR link with mentor for grading
Assignment Repository Structure
src
โโโ main
โ โโโ java
โ โ โโโ MainExercises.java # REQUIRED
โ โ โโโ BonusExercises.java # OPTIONAL
โ โโโ resources
โโโ test
โโโ java
โโโ MainTestPartitions.java
โโโ MainTestTriangle.java
โโโ MainTestTraversal.java
โโโ BonusTestDates.java
โโโ BonusTestEmail.java
โโโ BonusTestPalindromes.java
โโโ BonusTestPasswords.java
Maven Configuration
- JUnit for unit testing
- Reload Maven projects after configuration changes
- Network mirror setup for restricted environments
๐ Slides & Materials
- ๐งโ๐ซ TA Workshop Slides (PDF)
- ๐ฅ Workshop Recording
- ๐ฅ Assignment Explanation Videos
๐ ๏ธ Workshop & Assignments
- ๐ฌ Workshop
- Installing and setting up Git
- Creating Git.Meshcomp account
- Pushing a project to your account
- ๐งฎ Assignments
- HW-02-git-and-java-practice
- Three Java problems to solve
- Complete Git workflow (fork, branch, PR)
๐ Repository
- ๐ Workshop Repository - Git and Java practice assignment
- ๐ Note: Workshop focused on Git installation and setup, while the assignment combines Git workflow with Java implementation
๐ Additional Resources
- Git Documentation
- Markdown Documentation
- Git Cheat Sheet
- Git Tutorial - Faradars
- Maven Mirror Configuration
โฉ Navigation
Tip :
Mastering Git is as important as learning Java! The Git workflow (fork โ branch โ commit โ push โ PR) will be used for every assignment and project in this course. Practice the commands until they become second nature, and always watch the introductory videos before starting assignments. Remember:
git statusis your best friend โ use it frequently to understand whatโs happening in your repository!