๐Ÿงญ 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:
    1. Make changes to files
    2. git add - stage changes
    3. git commit - save snapshot

Starting a Project from Scratch

  • git init:
    • Transforms a regular directory into a Git-managed repository
    • Creates a hidden .git folder 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.xml in ~/.m2/ directory
    • Use mirror: https://maven.devneeds.ir/
  • 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
  • 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


๐Ÿ› ๏ธ Workshop & Assignments

  • ๐Ÿ’ฌ Workshop
    • Installing and setting up Git
    • Creating Git.Meshcomp account
    • Pushing a project to your account
  • ๐Ÿงฎ Assignments

๐Ÿ”— 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


โฉ 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 status is your best friend โ€“ use it frequently to understand whatโ€™s happening in your repository!