top of page

Creating a New Repository in Git

You want to start a new software project and need to create a Git repository to track changes in your code.


Instructions:


Objective: The objective of this assignment is to familiarize you with the process of creating a new Git repository and managing it using Git commands. You will create a new repository, make commits, and interact with a remote repository.

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: 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.

5. Task 5: Add some content to the "README.md" file using a text editor or a command-line text editor like Vim or Nano.

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

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


Part 2: Remote Repository Setup

1. Task 1: Create a new account on a Git hosting platform such as GitHub (https://github.com/), GitLab (https://about.gitlab.com/), or Bitbucket (https://bitbucket.org/). If you already have an account, you can use it.

2. Task 2: Create a new empty repository on the Git hosting platform. Name it "GitAssignment."

3. Task 3: Link your local Git repository (the "GitAssignment" folder) to the remote repository you just created. Use the relevant Git remote command to do this.

4. Task 4: Push your local repository to the remote repository.


Part 3: Collaboration

1. Task 1: Share the URL of your remote repository (e.g., the GitHub repository URL) with a classmate or a friend.

2. Task 2: Ask your classmate or friend to clone your repository to their local machine.

3. Task 3: Your classmate or friend should make a change to the "README.md" file (add some content or make modifications) in their local copy of the repository.

4. Task 4: They should commit their changes and push them to the remote repository (your repository).

5. Task 5: You should pull the changes made by your classmate or friend into your local repository.

6. Task 6: Verify that the changes are now reflected in your local "README.md" file.

Solutions


1. Task 1: Create a new directory/folder 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

   


5. Task 5: Add content to the "README.md" file using a text editor or command-line editor.

   

   nano README.md  # Use your preferred text editor

   


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

   

   git add README.md

   


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

   

   git commit -m "Initial commit - added README.md"

   


Part 2: Remote Repository Setup


1. Task 1: Create an account on a Git hosting platform.


2. Task 2: Create a new empty repository on the hosting platform.


3. Task 3: Link your local Git repository to the remote repository.

   

   git remote add origin <repository_url>

   


   Replace `<repository_url>` with the URL of your remote repository.


4. Task 4: Push your local repository to the remote repository.

   

   git push -u origin master

   


Part 3: Collaboration


1. Task 1: Share the URL of your remote repository.


2. Task 2: Your classmate or friend should clone your repository.

   

   git clone <repository_url>

   


3. Task 3: They should make changes to the "README.md" file.


4. Task 4: Commit and push their changes to the remote repository.

   

   git add README.md

   git commit -m "Updated README.md"

   git push origin master

   


5. Task 5: You should pull the changes made by your classmate or friend.

   

   git pull origin master

   


bottom of page