Learning Path: Introduction to GIT Basics

In this learning path, you will grasp the fundamental concepts of GIT, covering the creation of repositories, addition of new files, committing changes, reviewing logs, and utilizing branch and merge functions effectively.

Initializing a GIT Repository

To start with GIT, you need to create a new directory for your project and then initialize a git repository using the following command:

git init

This command creates a .git directory within your project directory to store all metadata and the object database for the repository. It sets up the directory for version control. Once executed successfully, you can proceed with other Git commands.

Practical Exercise

Let's walk through a practical exercise illustrated in the diagram provided.

  1. Initializing the Repository:

After running the git init command, we proceed to create an index.html file containing basic HTML tags. Additionally, we create a readme.md file and a bluestyles.css file using the following commands:

vi index.html
vi readme.md
vi bluestyles.css
  1. Adding Files to the Repository:
    Once the files are created, we add them to the repository using the following command:

     git add index.html
     git status
     git commit -m "c1 first release of index.html"
     git add bluestyles.css readme.cmd
    

    This command stages all three files for inclusion in the next commit. Second command is used to check the status of the staged files. The git status command displays the three new files in the staging environment, indicating that they are ready to be committed.

  2. Committing Changes:

    To commit the staged changes to the repository along with a descriptive message, we execute the following command:

     git commit -m "c2 added bluestyles.css and readme.cmd to rep"
    

    The -m option is used to provide a concise message that summarizes the changes made in this commit.

  3. Step 4 Git branch - running "git branch" without any argument list all branches in the repository. Branching allow for parallel development, enabling multiple lines of work to progress independently of each other.

    In the exercise, we will create branch called images, modify index.html to incorporate an image file reference. Below step enables to create a new branch named images and switch to the branch.

     git checkout -b images 
     git branch # to check current branch 
     vi index.html 
     git add index.html img1.jpg 
     git commit -m "c3 added new image, updated reference in index.html"
    

    Above commands, commits modified index.html and include img1.jpg file. We will go ahead and modify index.html and include img2.jpg file. This change is in staging and not commited.

  4. GIT Branch Merge: In this section, create a new branch called e-fix, modify html file a per business required, in this case, include a new line in file.

     git checkout -b efix 
     git status 
     git add index.html 
     git commit -m "c4 updated index.html with efix branch"
    

    Merget conflict arise when two developers modify the same part of a file independently. Changes made in one branch conflict with changes made in another branch. A branch is rebased onto another branch, causing conflicting change.

    Handling merge conflicts is a common aspect of collaborative development in Git and it requires clear communication and communication. In tihs case, master of the report reviews the conflict lines in the file and takes up the decision to resolve merge effectively.

     git checkout master
     git merge efix
     git branch -d efix
     git checkout images
     git add --all
     git commit -m "c5 add new image"
     git checkout master
     git status
     git merge images
     git add index.html
     git commit -m "c6 merge conflict included images"
     git branch -d images
     git log --oneline
    

    By following these steps, we establish a version-controlled environment where developers can manage changes efficiently and collaborate effectively.