Day-02: Introduction to Git & Github

Day-02: Introduction to Git & Github

what is git

Git is a distributed version control system used for tracking changes in source code during software development. It allows multiple developers to collaborate on projects by providing features such as branching, merging, and version tracking. With Git, developers can work on different features or fixes simultaneously without interfering with each other's work. It's widely used in the software development industry and is particularly popular for its efficiency, speed, and flexibility.

Benefits of git:

  • version Control: Git allows you to keep track of changes made to your codebase over time, making it easy to revert to previous versions if needed.

  • Collaboration: Multiple developers can work on the same project simultaneously without interfering with each other's changes. Git facilitates collaboration by providing tools for merging and managing conflicts.

  • Branching: Git's branching model allows developers to work on new features or experimental changes in isolated environments, which can later be merged into the main codebase.

  • Distributed: Each developer has a complete copy of the project's history, enabling them to work offline and independently. Changes can be synchronized with remote repositories when online.

  • Speed and Performance: Git is designed to be fast and efficient, even with large codebases. Operations like committing changes, branching, and merging are typically performed quickly.

  • Open Source and Community Support: Git is open-source software, which means it's free to use and has a large community of users and contributors who provide support, resources, and extensions (like GitLab, GitHub).

  • Backup and Disaster Recovery: By hosting repositories on remote servers (such as GitHub, GitLab, or Bitbucket), Git provides a form of backup and disaster recovery for your codebase.

  • Traceability and Accountability: Git tracks who made which changes and when, providing transparency and accountability within development teams.

  • Customizability: Git's flexibility allows developers to customize their workflows and integrate it with other tools and services through APIs and hooks.

what is github

GitHub is a web-based platform used for version control and collaboration on software projects. It provides hosting for Git repositories, which are a type of version control system.

Git allows developers to track changes to their codebase, collaborate with others, and manage different versions of their software. GitHub enhances Git by adding features like issue tracking, pull requests, wikis, and project management tools, making it a central hub for developers to work together on coding projects.

Types of version control system:

There are two main type of version control system: centralized version control systems and distributed version control systems.

Distributed Version Control (DVCS)centralized version control systems
Each user has a full copy of the repository, including its history, locally.All users access a central repository for version control.
Branching is lightweight and powerful, allowing users to create and merge branches easily.Branching is less flexible and typically used for major releases or feature branches.
Users can work offline, making commits and other changes locally without needing an internet connection.Users need a constant connection to the central server to perform most version control operations
Optimized for speed and performance, enabling quick operations even with large repositories.Operations may become slower, especially with large repositories or when network connectivity is poor.
No dependency on a central server; users have full control over their repositories.Relies on a central server for repository storage and version control operations
Git, MercurialSubversion (SVN), Concurrent Versions System (CVS)

Basic Git cheat sheet covering some common commands and their usage:

Certainly! Here's a basic Git cheat sheet covering some common commands and their usage:

Setup

  • git init: Initialize a new Git repository in the current directory.

  • git clone [repository URL]: Clone an existing repository from a remote URL.

Basic Commands

  • git add [file(s)]: Add file(s) to the staging area.

  • git commit -m "[commit message]": Commit staged changes with a descriptive message.

  • git status: Check the status of the working directory and staging area.

  • git diff: Show the changes between the working directory and the staging area.

Branching

  • git branch: List all branches in the repository.

  • git branch [branch name]: Create a new branch.

  • git checkout [branch name]: Switch to a different branch.

  • git merge [branch name]: Merge changes from a specified branch into the current branch.

Remote Repository

  • git remote: List remote repositories.

  • git remote add [name] [URL]: Add a remote repository.

  • git push [remote name] [branch name]: Push commits to a remote repository.

  • git pull [remote name] [branch name]: Fetch and merge changes from a remote repository.

History and Undo

  • git log: Show commit history.

  • git reset --hard [commit hash]: Reset the repository to a specific commit, discarding all changes after it.

  • git revert [commit hash]: Revert a specific commit, creating a new commit to undo its changes.

  • git checkout -- [file]: Discard changes in a specific file and revert it to the last committed version.

Miscellaneous

  • git config: Configure Git settings (e.g., username, email).

  • git rm [file(s)]: Remove file(s) from the working directory and staging area.

  • git mv [old file] [new file]: Move or rename a file, staging the change.

some basic command for transfering file local repojetory to remote repojetory:

git initInitialize a new Git repository in the current directory
git Add .Add a file to a current directory
git commit -m "first commit"Commit staged changes with a descriptive message.
git branch -M mainCreate a new branch
git remote add origin github.com:wahid08034/Docker-zero-hero.gitAdd a remote repository.
git push -u origin (branch name)Push commits to a remote repository.