Skip to main content

Experiment No. 1 Title : Exploring Git Commands through Collaborative Coding.

 Experiment No. 1

Title : Exploring Git Commands through Collaborative Coding.


Objective:

The objective of this experiment is to familiarise participants with essential Git concepts and commands, enabling them to effectively use Git for version control and collaboration.



Introduction:


Git is a distributed version control system (VCS) that helps developers track changes in their codebase, collaborate with others, and manage different versions of their projects efficiently. It was created by Linus Torvalds in 2005 to address the shortcomings of existing version control systems.


Unlike traditional centralised VCS, where all changes are stored on a central server, Git follows a distributed model. Each developer has a complete copy of the repository on their local machine, including the entire history of the project. This decentralisation offers numerous advantages, such as offline work, faster operations, and enhanced collaboration.


Git is a widely used version control system that allows developers to collaborate on projects, track changes, and manage codebase history efficiently. This experiment aims to provide a hands-on introduction to Git and explore various fundamental Git commands. Participants will learn how to set up a Git repository, commit changes, manage branches, and collaborate with others using Git.



Key Concepts:


  • Repository: A Git repository is a collection of files, folders, and their historical versions. It contains all the information about the project's history, branches, and commits.

  • Commit: A commit is a snapshot of the changes made to the files in the repository at a specific point in time. It includes a unique identifier (SHA-1 hash), a message describing the changes, and a reference to its parent commit(s).

  • Branch: A branch is a separate line of development within a repository. It allows developers to work on new features or bug fixes 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 a feature branch into the main branch or any other target branch.

  • Pull Request: In Git hosting platforms like GitHub, a pull request is a feature that allows developers to propose changes from one branch to another. It provides a platform for code review and collaboration before merging.

  • Remote Repository: A remote repository is a copy of the Git repository stored on a server, enabling collaboration among multiple developers. It can be hosted on platforms like GitHub, GitLab, or Bitbucket.


Basic Git Commands:


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

  • git clone: Creates a copy of a remote repository on your local machine.

  • git add: Stages changes for commit, preparing them to be included in the next commit.

  • git commit: Creates a new commit with the staged changes and a descriptive message.

  • git status: Shows the current status of the working directory, including tracked and untracked files.

  • git log: Displays a chronological list of commits in the repository, showing their commit messages, authors, and timestamps.

  • git branch: Lists, creates, or deletes branches within the repository.

  • git checkout: Switches between branches, commits, or tags. It's used to navigate through the repository's history.

  • git merge: Combines changes from different branches, integrating them into the current branch.

  • git pull: Fetches changes from a remote repository and merges them into the current branch.

  • git push: Sends local commits to a remote repository, updating it with the latest changes.




Materials:

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

  • Command-line interface (Terminal, Command Prompt, or Git Bash)


Experiment Steps:

Step 1: Setting Up Git Repository

  • Open the command-line interface on your computer.

  • Navigate to the directory where you want to create your Git repository.

  • Run the following commands:


git init

  • This initialises a new Git repository in the current directory.




Step 2: Creating and Committing Changes

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

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

  • In the command-line interface, run the following commands:

git status

  • This command shows the status of your working directory, highlighting untracked files.


git add example.txt

  • This stages the changes of the "example.txt" file for commit.


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

  • This commits the staged changes with a descriptive message.



Step 3: Exploring History

Modify the content of "example.txt."

Run the following commands:


git status

  • Notice the modified file is shown as "modified."



git diff

  • This displays the differences between the working directory and the last commit.


git log

  • This displays a chronological history of commits.


Step 4: Branching and Merging

Create a new branch named "feature" and switch to it:



git branch feature

git checkout feature

or shorthand:


git checkout -b feature

  • Make changes to the "example.txt" file in the "feature" branch.

  • Commit the changes in the "feature" branch.

  • Switch back to the "master" branch:

git checkout master


  • Merge the changes from the "feature" branch into the "master" branch:

git merge feature



Step 5: Collaborating with Remote Repositories

  • Create an account on a Git hosting service like GitHub (https://github.com/).

  • Create a new repository on GitHub.


  • Link your local repository to the remote repository:

git remote add origin <repository_url>

  • Push your local commits to the remote repository:

git push origin master


Conclusion:

Through this experiment, participants gained a foundational understanding of Git's essential commands and concepts. They learned how to set up a Git repository, manage changes, explore commit history, create and merge branches, and collaborate with remote repositories. This knowledge equips them with the skills needed to effectively use Git for version control and collaborative software development.



Exercise:

  1. Explain what version control is and why it is important in software development. Provide examples of version control systems other than Git.

  2. Describe the typical workflow when working with Git, including initialising a repository, committing changes, and pushing to a remote repository. Use a real-world example to illustrate the process.

  3. Discuss the purpose of branching in Git and how it facilitates collaborative development. Explain the steps involved in creating a new branch, making changes, and merging it back into the main branch.

  4. What are merge conflicts in Git, and how can they be resolved? Provide a step-by-step guide on how to handle a merge conflict.

  5. Explain the concept of remote repositories in Git and how they enable collaboration among team members. Describe the differences between cloning a repository and adding a remote.

  6. Discuss different branching strategies, such as feature branching and Gitflow. Explain the advantages and use cases of each strategy.

  7. Describe various Git commands and techniques for undoing changes, such as reverting commits, resetting branches, and discarding uncommitted changes.

  8. What are Git hooks, and how can they be used to automate tasks and enforce coding standards in a Git repository? Provide examples of practical use cases for Git hooks.

  9. List and explain five best practices for effective and efficient Git usage in a collaborative software development environment.

  10. Discuss security considerations in Git, including how to protect sensitive information like passwords and API keys. Explain the concept of Git signing and why it's important.

Comments

Popular posts from this blog

Experiment No. 5 Title: Applying CI/CD Principles to Web Development Using Jenkins, Git, and Local HTTP Server

  Experiment No. 5 Title: Applying CI/CD Principles to Web Development Using Jenkins, Git, and Local HTTP Server  Objective: The objective of this experiment is to set up a CI/CD pipeline for a web development project using Jenkins, Git, and webhooks, without the need for a Jenkinsfile. You will learn how to automatically build and deploy a web application to a local HTTP server whenever changes are pushed to the Git repository, using Jenkins' "Execute Shell" build step. Introduction: Continuous Integration and Continuous Deployment (CI/CD) is a critical practice in modern software development, allowing teams to automate the building, testing, and deployment of applications. This process ensures that software updates are consistently and reliably delivered to end-users, leading to improved development efficiency and product quality. In this context, this introduction sets the stage for an exploration of how to apply CI/CD principles specifically to web development using J

Experiment No. 10 Title: Create the GitHub Account to demonstrate CI/CD pipeline using Cloud Platform.

  Experiment No. 10 Title: Create the GitHub Account to demonstrate CI/CD pipeline using Cloud Platform. Objective: The objective of this experiment is to help you create a GitHub account and set up a basic CI/CD pipeline on GCP. You will learn how to connect your GitHub repository to GCP, configure CI/CD using Cloud Build, and automatically deploy web pages to an Apache web server when code is pushed to your repository. Introduction: Continuous Integration and Continuous Deployment (CI/CD) pipelines are essential for automating the deployment of web applications. In this experiment, we will guide you through creating a GitHub account and setting up a basic CI/CD pipeline using Google Cloud Platform (GCP) to copy web pages for an Apache HTTP web application. Continuous Integration and Continuous Deployment (CI/CD) is a crucial practice in modern software development. It involves automating the processes of code integration, testing, and deployment to ensure that software changes are co

Experiment No. 6 Title: Exploring Containerization and Application Deployment with Docker

  Experiment No. 6 Title: Exploring Containerization and Application Deployment with Docker  Objective: The objective of this experiment is to provide hands-on experience with Docker containerization and application deployment by deploying an Apache web server in a Docker container. By the end of this experiment, you will understand the basics of Docker, how to create Docker containers, and how to deploy a simple web server application. Introduction Containerization is a technology that has revolutionised the way applications are developed, deployed, and managed in the modern IT landscape. It provides a standardised and efficient way to package, distribute, and run software applications and their dependencies in isolated environments called containers. Containerization technology has gained immense popularity, with Docker being one of the most well-known containerization platforms. This introduction explores the fundamental concepts of containerization, its benefits, and how it differs