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:
Explain the difference between Git and GitHub.
What is a GitHub repository? How is it different from a Git repository?
Describe the purpose of a README.md file in a GitHub repository.
How do you create a new repository on GitHub? What information is required during the creation process?
Define what a pull request (PR) is on GitHub. How does it facilitate collaboration among developers?
Describe the typical workflow of creating a pull request and having it merged into the main branch.
How can you address and resolve merge conflicts in a pull request?
Explain the concept of forking a repository on GitHub. How does it differ from cloning a repository?
What is the purpose of creating a local clone of a repository on your machine? How is it done using Git commands?
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
Post a Comment