Introduction
In software development, Git and GitHub are two important tools for cooperation and version control. While people often use these terms in the same way, they have distinct roles. Git is a powerful version control system that helps developers manage their code effectively. It has a cool feature called "branching and merging," enabling developers to work on separate features or bug fixes without affecting the main code. This keeps things organized. Git also offers options like "reverting changes" and "rebasing" to maintain a neat commit history.
What is Git?
Git is a tool used by developers to keep track of changes in their code while building software. It records every change made to the project, making it easy to see how the code evolved over time. It also lets multiple developers work together smoothly, manage changes, and go back to previous versions if needed. Created by Linus Torvalds in 2005, Git is now widely used in the software development industry.
Key Concepts of Git:
Repository (Repo): A repository is a directory that contains your project files along with all the version history and metadata. It is where all the changes to your code are tracked.
Commit: A commit is a snapshot of your code at a specific point in time. It represents a set of changes that you want to save. Each commit has a unique identifier.
Branch: A branch is a separate line of development within a repository. It allows multiple developers to work on different features or bug fixes simultaneously without affecting the main codebase. Branches can be merged back into the main branch when the changes are ready.
Merge: Merging is the process of combining changes from one branch into another. It integrates the changes made in one branch into another branch.
Pull Request (PR): In Git-based collaboration, a pull request is a request to merge changes from one branch into another. It's commonly used in open-source projects and team collaboration to review and discuss code changes before merging.
Clone: Cloning a repository creates a copy of the entire repository on your local machine. This allows you to work on the code locally and contribute changes back to the original repository.
Fetch and Pull: Fetch retrieves changes from a remote repository without merging them, while pull fetches the changes and merges them into your local branch.
Push: Pushing refers to sending your local commits to a remote repository. This is how changes made on your local machine are shared with others.
Github:
GitHub is a web-based platform that provides hosting for software development and version control using Git.
It offers a wide range of features that make it easier for developers to collaborate, manage code, track changes, and work on projects together.GitHub has become a go-to platform for developers to share, collaborate, and contribute to projects. Besides enabling version control, GitHub allows developers to manage issues, track project progress, and even host open-source projects.
GitHub is widely used by individuals, teams, and organizations for open-source and private software development.
Key Features of Github:
Version Control: GitHub uses Git as its underlying version control system, allowing developers to track changes to their code over time. This helps teams collaborate on code, manage different versions, and easily revert to previous states if needed.
Repositories: Repositories, or "repos," are where code and project files are stored. Each repository has its URL and can be either public (visible to everyone) or private (accessible only to authorized users).
Collaboration: GitHub facilitates collaboration through features like pull requests and code reviews. Developers can fork a repository (create their copy) to work on changes, then submit pull requests to propose changes for integration into the original repository. Code reviews allow others to provide feedback before changes are merged.
Issues and Projects: GitHub provides tools for issue tracking and project management. Developers can create issues to track bugs, feature requests, and tasks. Projects allow you to organize and manage work using Kanban-style boards.
GitHub Actions: GitHub Actions is a continuous integration and automation platform built into GitHub. It allows you to automate workflows, run tests, and deploy code based on events and triggers.
GitHub Pages: GitHub Pages lets you host static websites directly from your GitHub repository. It's commonly used for documentation, project websites, or personal blogs.
Difference Between Git and GitHub:
Git: Git is a decentralized revision control system used to monitor modifications in source code throughout software development. It facilitates collaboration among programmers, delivering swiftness, data accuracy, and assistance for distributed non-linear workflows.
GitHub: GitHub is an internet-based hosting service for Git repositories, presenting all the decentralized version control and source code management capabilities of Git, in addition to its extra functionalities.
Version Control and its Types:
Version control is like a time machine for developers. It helps them keep track of changes they make to their code or files, so they can easily go back to previous versions if something goes wrong. It's like having a safety net for their work. There are two main types of version control systems:
Centralized Version Control System (CVCS): CVCS is like a big library where all the code and files are stored in one central place. Developers have to connect to this library whenever they want to save or retrieve their work. However, this approach has some drawbacks, like always needing an internet connection to access the library, the risk of the library failing, and it's not so great for multiple people working together at the same time.
Distributed Version Control System (DVCS): DVCS, as the name suggests, distributes the complete repository to each developer's local machine, including the entire version history and all branches. This distribution provides numerous advantages over CVCS:
Offline functionality: Developers can perform version control operations without an internet connection, making it convenient for remote or travel situations.
Distribution: Each developer's repository acts as a backup, ensuring data preservation even if the central server encounters issues.
Branching and Merging: DVCS simplifies branching and merging operations, enabling parallel development and efficient code integration.
Collaboration and Diverging: DVCS platforms like Git encourage open-source development and community involvement through easy collaboration and diverging of repositories.
Flexibility and Customization: Teams can tailor workflows and processes to suit their specific needs, enhancing development practices.
Speed and Performance: Most DVCS operations are local, resulting in faster and more responsive version control actions compared to CVCS.
Enhanced Accessibility: DVCS platforms are typically hosted on multiple servers or cloud-based platforms, ensuring better availability and uptime.
Installation of Git
For Windows
Download and install GIT on your local machine (desktop/laptop) https://git-scm.com/downloads
Validate Git Status locally using the below
command-
Install and configure Github for Desktop https://desktop.github.com/
For Amazon Linux EC2
sudo yum update
sudo yum install git
git --version
Create your account on Github
Local & Remote Repository:
Local Repository:
A local repository is a complete replica of the project's version history stored on your local machine. It contains all the project files, commits history and branches.
When you work on your project, you make modifications in the local repository and save those changes as commits before sharing them with others. This setup enables you to work offline and commit changes regularly without needing an internet connection.
Remote Repository:
A remote repository is located on a remote server or a cloud-based platform like GitHub, GitLab, or Bitbucket. It serves as a centralized hub where multiple developers can collaborate on the same project.
The remote repository acts as the central source of truth, allowing developers to share their changes with others and pull changes made by others into their local repositories
Creating a New Repository on GitHub:
Log in to your GitHub account (github.com).
Click on the "+" icon in the right corner of the homepage and select "New repository."
Provide the required details for the new repository.
Click "Create repository."
Basic Commands
git init
git init will create a new local GIT repository. The following Git command will create a repository in the current directory
Alternatively, you can create a repository within a new directory by specifying the project name:
git init [project name]
git clone
git clone is used to copy a repository. If the repository lies on a remote server, use
To clone the repository to your local machine, click on "CODE" on the github repository's main page to get the repository's path.
git commit
git commit will create a snapshot of the changes and save it to the git directory
git commit -m "Add this new file to git-repo01"
git add
git add is used to add files to the staging area. For example, the basic Git following command will index the test1.txt file:
git status
git status displays the list of changed files together with the files that are yet to be staged or committed.
git log
The git log command is used to display the commit history of a Git repository. When you run git log in your repository, it will show a list of commits in reverse chronological order, with the most recent commit at the top.
git rm
The "git rm" command helps you to remove files from a Git repository. It allows you to not only delete a file from the repository but also it remove file from working directory.
git rm -r
This command is used to remove an entire directory and its contents from both the working directory and the Git repository
Conclusion
Git and GitHub are essential tools for software development. Git helps developers track changes and collaborate efficiently, while GitHub provides a user-friendly platform for hosting and sharing projects. Understanding Git and GitHub basics empowers developers to work better together, manage code effectively, and tackle complex tasks with ease. Embrace these tools to improve your development skills and contribute to successful projects. Let Git and GitHub be your allies in the world of software development, making coding a rewarding and enjoyable experience. Happy coding!
hope this explanation helps you understand some of the important terminologies in Git and Github.
Stay tuned for the next part 2. I will keep sharing my learnings and knowledge here with you.
Thank you,
Neha Bawane