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

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-plugin -->     </plugins> </build> Depend

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

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