Science Knowings: JavaScript Course For Social Media

Version Control Systems (Git)

Version Control with Git

Welcome to Git!

Surprise! We're exploring version control systems, like Git. Git helps us keep track of changes in our code and collaborate effectively.

In this session, we'll dive into the basics of Git.

Why Git?

Version Control with Git

  • Track changes in your code
  • Collaboration with other developers
  • Maintain multiple versions of your code

Benefits of Using Git

  • Version history
  • Code backups
  • Team collaboration
  • Easy deployment

Getting Started with Git

Installing Git

  • macOS: brew install git
  • Windows: Download from git-scm.com

Initialize a Git Repository

  • git init

Add Files to Git

  • git add <filename>

Basic Git Commands

Basic Git Commands

  • git status: Show the current state of the working tree
  • git add: Add files to the staging area
  • git commit: Create a snapshot of the changes
  • git log: View the history of commits

Staging Changes

Staging Changes

  • The staging area (also known as the index) is a holding area for changes before committing.
  • git add moves changes from the working tree to the staging area.
  • Only staged changes will be included in the next commit.

Committing Changes

Committing Changes

  • Create a permanent snapshot of the changes in the staging area.
  • git commit -m "Commit message"
  • Commit message should briefly describe the changes made.

Tracking Changes with Git

Tracking Changes with Git

  • Git tracks changes in files over time.
  • Use git diff to compare changes between commits.
  • git checkout allows you to switch between different versions of your code.

Branching and Merging

Branching and Merging

  • Branching: Create separate lines of development without affecting the main branch.
  • git branch <branch_name>
  • Merging: Combine changes from different branches into a single branch.
  • git merge <branch_name>

Resolving Merge Conflicts

Resolving Merge Conflicts

  • When merging branches, conflicts may occur due to conflicting changes.
  • Git will mark the conflicting sections with <<<<<<<<, =======, >>>>>>>>.
  • Manually resolve the conflicts and commit the changes.

Working with Remote Repositories

Working with Remote Repositories

  • Store your Git repository on a remote server (e.g., GitHub, GitLab).
  • Push local changes to the remote repository: git push
  • Pull changes from the remote repository: git pull

Push and Pull Requests

Push and Pull Requests

  • Push Request: Submit your changes for review and merging.
  • Pull Request: Request changes from other developers to be merged into your branch.
  • Collaborate on code changes and maintain code quality.

Git Workflows

Git Workflows

  • Common Workflows:
  • Centralized (single main branch)
  • Forking (creating branches from a remote repository)
  • Feature Branching (working on specific features in separate branches)

Choose the workflow that suits your team and project best.

Advanced Git Features

Advanced Git Features

  • Rebasing: Reorganize commit history by combining or squashing commits.
  • Cherry-Picking: Select and apply specific commits from one branch to another.
  • Stashing: Temporarily save and untrack changes without committing.

Explore these features to enhance your Git skills.

Next Up: Continuous Integration (CI)

Next Up: Continuous Integration

Automate your build, test, and deployment processes.
Ensure code quality and maintain consistent software delivery.
Follow us to learn more!