Skip to main content

Experiment No. 2 Title: Implement GitHub Operations using Git.

 Experiment No. 2

Title: Implement GitHub Operations using Git.


Objective:

The objective of this experiment is to guide you through the process of using Git commands to interact with GitHub, from cloning a repository to collaborating with others through pull requests.


Introduction:

GitHub is a web-based platform that offers version control and collaboration services for software development projects. It provides a way for developers to work together, manage code, track changes, and collaborate on projects efficiently. GitHub is built on top of the Git version control system, which allows for distributed and decentralised development.


Key Features of GitHub:

  • Version Control: GitHub uses Git, a distributed version control system, to track changes to source code over time. This allows developers to collaborate on projects while maintaining a history of changes and versions.

  • Repositories: A repository (or repo) is a collection of files, folders, and the entire history of a project. Repositories on GitHub serve as the central place where code and project-related assets are stored.

  • Collaboration: GitHub provides tools for team collaboration. Developers can work together on the same project, propose changes, review code, and discuss issues within the context of the project.

  • Pull Requests: Pull requests (PRs) are proposals for changes to a repository. They allow developers to submit their changes for review, discuss the changes, and collaboratively improve the code before merging it into the main codebase.

  • Issues and Projects: GitHub allows users to track and manage project-related issues, enhancements, and bugs. Projects and boards help organize tasks, track progress, and manage workflows.

  • Forks and Clones: Developers can create copies (forks) of repositories to work on their own versions of a project. Cloning a repository allows developers to create a local copy of the project on their machine.

  • Branching and Merging: GitHub supports branching, where developers can create separate lines of development for features or bug fixes. Changes made in branches can be merged back into the main codebase.

  • Actions and Workflows: GitHub Actions enable developers to automate workflows, such as building, testing, and deploying applications, based on triggers like code pushes or pull requests.

  • GitHub Pages: This feature allows users to publish web content directly from a GitHub repository, making it easy to create websites and documentation for projects.


Benefits of Using GitHub:


  • Collaboration: GitHub facilitates collaborative development by providing tools for code review, commenting, and discussion on changes.

  • Version Control: Git's version control features help track changes, revert to previous versions, and manage different branches of development.

  • Open Source: GitHub is widely used for hosting open-source projects, making it easier for developers to contribute and for users to find and use software.

  • Community Engagement: GitHub fosters a community around projects, enabling interaction between project maintainers and contributors.

  • Code Quality: The code review process on GitHub helps maintain code quality and encourages best practices.

  • Documentation: GitHub provides a platform to host project documentation and wikis, making it easier to document codebases and project processes.

  • Continuous Integration/Continuous Deployment (CI/CD): GitHub Actions allows for automating testing, building, and deploying applications, streamlining the development process.


Materials:

  • Computer with Git installed (https://git-scm.com/downloads)

  • GitHub account (https://github.com/)

  • Internet connection


Experiment Steps:


Step 1: Cloning a Repository

  • Sign in to your GitHub account.

  • Find a repository to clone (you can use a repository of your own or any public repository).

  • Click the "Code" button and copy the repository URL.

  • Open your terminal or command prompt.

  • Navigate to the directory where you want to clone the repository.

  • Run the following command:


git clone <repository_url>


  • Replace <repository_url> with the URL you copied from GitHub.

  • This will clone the repository to your local machine.


Step 2: Making Changes and Creating a Branch


Navigate into the cloned repository:


cd <repository_name>

  • Create a new text file named "example.txt" using a text editor.

  • Add some content to the "example.txt" file.

  • Save the file and return to the command line.

  • Check the status of the repository:

git status


  • Stage the changes for commit:

git add example.txt


  • Commit the changes with a descriptive message:

git commit -m "Add content to example.txt"


  • Create a new branch named "feature":

git branch feature


  • Switch to the "feature" branch:

git checkout feature



Step 3: Pushing Changes to GitHub

  • Add Repository URL in a variable 

git remote add origin  <repository_url>

  • Replace <repository_url> with the URL you copied from GitHub.


  • Push the "feature" branch to GitHub:

git push origin feature

  • Check your GitHub repository to confirm that the new branch "feature" is available.


Step 4: Collaborating through Pull Requests

  • Create a pull request on GitHub:

  • Go to the repository on GitHub.

  • Click on "Pull Requests" and then "New Pull Request."

  • Choose the base branch (usually "main" or "master") and the compare branch ("feature").

  • Review the changes and click "Create Pull Request."

  • Review and merge the pull request:

  • Add a title and description for the pull request.

  • Assign reviewers if needed.

  • Once the pull request is approved, merge it into the base branch.


Step 5: Syncing Changes

  • After the pull request is merged, update your local repository:

git checkout main

git pull origin main


Conclusion:

This experiment provided you with practical experience in performing GitHub operations using Git commands. You learned how to clone repositories, make changes, create branches, push changes to GitHub, collaborate through pull requests, and synchronise changes with remote repositories. These skills are essential for effective collaboration and version control in software development projects using Git and GitHub.


Questions:

  1. Explain the difference between Git and GitHub.

  2. What is a GitHub repository? How is it different from a Git repository?

  3. Describe the purpose of a README.md file in a GitHub repository.

  4. How do you create a new repository on GitHub? What information is required during the creation process?

  5. Define what a pull request (PR) is on GitHub. How does it facilitate collaboration among developers?

  6. Describe the typical workflow of creating a pull request and having it merged into the main branch.

  7. How can you address and resolve merge conflicts in a pull request?

  8. Explain the concept of forking a repository on GitHub. How does it differ from cloning a repository?

  9. What is the purpose of creating a local clone of a repository on your machine? How is it done using Git commands?

  10. Describe the role of GitHub Issues and Projects in managing a software development project. How can they be used to track tasks, bugs, and enhancements?


Comments

Popular posts from this blog

Example of Maven project that interacts with a MySQL database and includes testing

Example Maven project that interacts with a MySQL database and includes testing To install Java, MySQL, Maven, and write a Java program to fetch table data, execute, and create a JAR file using Maven on Ubuntu, you can follow these steps: Step 1: Install Java You can install Java using the following commands: sudo apt update sudo apt install default-jre sudo apt install default-jdk Verify the installation by running: java -version Step 2: Install MySQL You can install MySQL using the following commands: sudo apt update sudo apt install mysql-server During the installation, you'll be prompted to set a root password for MySQL or you can set password at latter stage using following steps.  sudo mysql ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; exit Step 3: Install Maven You can install Maven using the following commands: sudo apt update sudo apt install maven Verify the installation by running: mvn -version Step 4: Create ...

Maven Create and Build Artifacts

In Maven, you can create and build artifacts using the package phase of the build lifecycle. The package phase is responsible for taking the compiled code and other project resources and packaging them into a distributable format, such as a JAR (Java Archive), WAR (Web Application Archive), or other custom formats. Here are the steps to create and build artifacts using Maven: Configure the Build Output: In your project's pom.xml file, you need to configure the output of the build. This includes specifying the type of artifact you want to create (e.g., JAR, WAR) and any additional resources to include. You do this in the <build> section of your pom.xml: <build>     <finalName>my-artifact</finalName> <!-- Name of the artifact without the extension -->     <plugins>         <!-- Plugin configurations for creating the artifact -->         <!-- For example, maven-jar-plugin or maven-war-p...

Maven Repositories (local, central, global)

Maven relies on repositories to manage dependencies, plugins, and other artifacts required for a project. There are typically three types of repositories in Maven: local, central, and remote/global repositories. Local Repository: Location: The local repository is located on your local development machine. By default, it's in the .m2 directory within your user home directory (e.g., C:\Users\<username>\.m2\repository on Windows or /Users/<username>/.m2/repository on macOS and Linux). Purpose: The local repository is used to store artifacts (JARs, POMs, and other files) that your machine has downloaded or built during previous Maven builds. These artifacts are specific to your local development environment. Benefits: Using a local repository improves build performance since it caches dependencies locally, reducing the need to download them repeatedly. It also ensures reproducibility by maintaining a local copy of dependencies. Central Repository: Location: The central repo...