top of page

Adding and Committing Changes

Title: Adding and Committing Changes - Assignment


Objective: The objective of this assignment is to introduce you to the fundamental Git concepts of adding and committing changes. You will work with a local Git repository, make changes to files, stage those changes, and commit them.


Prerequisites: Before starting this assignment, ensure that you have Git installed on your computer. If not, please install it from [https://git-scm.com/](https://git-scm.com/).


Instructions:


Part 1: Setting Up a Local Repository 

1. Task 1: Create a new directory/folder on your computer for this assignment and name it "GitAssignment."


2. Task 2: Navigate to the "GitAssignment" directory in your terminal or command prompt.


3. Task 3: Initialize a new Git repository in this directory.


4. Task 4: Create a new text file named "README.md" in the repository.


Part 2: Making Changes 

1. Task 1: Open the "README.md" file using a text editor or a command-line text editor like Vim or Nano.


2. Task 2: Add some content to the "README.md" file. This can be any text you like, but make it meaningful (e.g., a short introduction about yourself).


3. Task 3: Save the changes to the "README.md" file.


Part 3: Staging Changes 

1. Task 1: Use the following Git command to check the status of your repository:

   

   git status

 

   Take note of the files listed as "modified."


2. Task 2: Add the "README.md" file to the staging area.

   

   git add README.md

   


Part 4: Committing Changes 


1. Task 1: Commit your changes with a meaningful commit message.

   

   git commit -m "Added content to README.md"

   

Part 5: Checking Commit History 


1. Task 1: Use the following Git command to view the commit history of your repository:


   git log

   

   Take note of the commit message, author, and timestamp of your latest commit.



Solutions

Here are the answers with commands for each part of the assignment:


Part 1: Setting Up a Local Repository


1. Task 1: Create a new directory for the assignment.

   

   mkdir GitAssignment

   

2. Task 2: Navigate to the "GitAssignment" directory.


    cd GitAssignment



3. Task 3: Initialize a new Git repository.

   

   git init   


4. Task 4: Create a new text file named "README.md."

   

   touch README.md   


Part 2: Making Changes


1. Task 1: Open the "README.md" file using a text editor or a command-line text editor.

   

   nano README.md  # Use your preferred text editor   


2. Task 2: Add some content to the "README.md" file. For example:


   

   # My Git Assignment


   This is my Git assignment.

   


3. Task 3: Save the changes to the "README.md" file and exit the text editor (in Nano, press `Ctrl + O` to save and `Ctrl + X` to exit).


Part 3: Staging Changes


1. Task 1: Check the status of your repository.


   

   git status

  


   This should show the "README.md" file as "modified."


2. Task 2: Add the "README.md" file to the staging area.

   

   git add README.md

   


Part 4: Committing Changes


1. Task 1: Commit your changes with a meaningful commit message.

   

   git commit -m "Added content to README.md"

   

Part 5: Checking Commit History


1. Task 1: View the commit history of your repository.


     git log

 

   This will display the commit history, including your latest commit, with information such as commit message, author, and timestamp.


bottom of page