# GIT & it's Usage

**Module-1\_GIT\_Assignment**

**(GIT and its usage)**

1. Initiates a new local Git Repo named  **practice-repo,** create a [readme.md](http://readme.md) file and commit the file to local repo.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698580950389/4d505afc-7006-42c6-853a-0a40c44cf4b0.png align="center")
    
2. Clone a specific branch from a remote GitHub repo.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698596354908/82c67423-7469-4948-ab9a-e0973ff1b5bb.png align="center")
    
3. Clone a new repo from github remote and checkin a file on your EC2 instance. Use ssh-keygen to generate keys and upload the keys on remote github profile.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1699682794652/56244c30-5dd9-4f3a-9a67-a77610fc8b20.png align="center")
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1699683313358/97a4edaf-a8da-4b05-84b6-3216cce1ffeb.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1699683636212/2870bd3b-d210-44a7-be30-e8864d6aaa21.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1699683953705/445be956-f62f-46ca-8f65-074511428b6f.png align="center")

1. [Understand Markdown syntax and Create a README.MD with the following content -](https://github.com/hams77)
    
    # [**Hi 👋, I'm** **&lt;your name&gt;**](https://github.com/hams77)
    
    ### [**&lt;your name&gt; is a passionate DevOps Engineer from India, working on Cloud and DevOps for 1+ years now.**](https://github.com/hams77)
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1699719651347/7827a357-bfc5-4ef7-8754-c1865d1a8261.png align="center")
    
    [https://github.com/hams77](https://github.com/hams77)
    
2. Github desktop and Git extensions on your local and view about the branches are setup. Checkin a file and commit to remote repo using Git extensions.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698997862374/ce1cd9ef-9cb2-4aa7-8d5d-b73c6ba03145.png align="left")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698998402388/afdd5cf3-ccfb-4e31-bc26-b500e04c8ec0.png?auto=compress,format&format=webp align="left")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698834363857/d3ac2b12-c60c-4aab-84ae-a89fd143ea8a.png?auto=compress,format&format=webp align="left")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1699002705687/a2344d70-c90c-4a26-8668-d216b35e9e2d.png?auto=compress,format&format=webp align="left")
    
3. How do you compare two branches using Git diff command. Explain the steps to have two create two branches with different contents and compare them.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698598284918/f391bcc3-b09a-4426-bc02-432b6e3c13aa.png align="center")
    
4. Explain the command git cherry-pick, and explain how it can be used.
    
    Cherry picking in Git is designed to apply some commit from one branch into another branch. It can be done if you eg. made a mistake and committed a change into wrong branch, but do not want to merge the whole branch. You can just eg. revert the commit and cherry-pick it on another branch.
    
    To use it, you just need git cherry-pick hash, where hash is a commit hash from other branch.
    
    The git **cherry-pick** command is used in Git to apply specific commits from one branch to another. It allows you to pick and choose individual commits from one branch and apply them to another branch, effectively transplanting changes from one branch to another. This can be useful when you want to selectively move specific changes between branches without merging the entire branch.
    
    git cherry-pick
    
    git checkout
    
    git cherry-pick
    
    git cherry-pick is a powerful tool for selectively applying changes between branches. It's particularly useful when you want to move specific features or bug fixes from one branch to another without merging the entire branch, maintaining a cleaner and more controlled commit history.
    
5. Explain the commands, git pull, merge and fetch.
    
    **git pull:**
    
    * git pull is a combination of two Git commands: git fetch and git merge. It is used to update your local repository with changes from a remote repository.
        
    * When you run git pull, Git will fetch the latest changes from the remote repository (by default, the remote repository is named "origin") and then automatically merge those changes into your current local branch.
        
    * If there are conflicts between the changes in the remote and your local branch, you will need to resolve these conflicts during the merge.
        
        **git merge:**
        
        * git merge is used to combine changes from one branch into another. It creates a new commit to integrate the changes.
            
        * To merge one branch into another, you first switch to the target branch (the branch you want to merge into) and then run git merge with the name of the source branch as an argument.
            
        * If there are conflicts between the branches being merged, you will need to resolve these conflicts manually.
            
            **git fetch:**
            
            * git fetch is used to retrieve updates from a remote repository without automatically merging them into your current local branch. It updates your local copy of the remote repository's branches, allowing you to see what changes have been made in the remote repository.
                
            * git fetch is useful for inspecting changes in the remote repository before deciding whether to merge them into your local branch using git merge.
                
                git pull is a combination of git fetch and git merge, which updates your local branch with changes from a remote repository and merges them automatically. git merge is used to explicitly combine changes from one branch into another, creating a new commit. git fetch is used to fetch updates from a remote repository without performing an automatic merge, allowing you to inspect the changes before merging.
                
6. Create a Jekyll Site using Github pages
    
    [https://pages.github.com/](https://github.com/hams77)
    
    [https://docs.github.com/en/pages/setting-up-a-github-pages-site-with-jekyll](https://github.com/hams77)
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1699685690191/aac09ff3-01b3-4a42-bf2b-9d83a9ade08d.png align="center")
    
7. How do you recover a deleted branch? Explain git reflog.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698901934940/68239d29-2cf0-444d-9e35-52e9a64696cc.png?auto=compress,format&format=webp align="left")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698902005472/784a280f-f169-487b-bf81-b47de7f4f505.png?auto=compress,format&format=webp align="left")
    
    We can recover a deleted branch in Git by using the git reflog and git checkout commands. The git reflog command is a powerful tool that displays a log of all reference changes in your Git repository, including branch deletions.
    
    The git reflog command will list all the recent reference changes in your repository, including branch creations and deletions. Each entry in the reflog has a unique SHA-1 commit hash, a description of the action, and the branch or commit it affected.
