Introduction to Git

Git is a distributed version control system that helps developers track changes to their code and collaborate with others effectively. It allows you to manage different versions of your code, work on new features without interfering with the main codebase, and merge changes from multiple contributors seamlessly.

Installation

  1. Install Git: Download and install Git from the official website (https://git-scm.com/downloads). Follow the installation instructions for your operating system.
  2. Configure Git: After installation, open a terminal or command prompt, and set your username and email address using the following commands:
bashCopy code
git config --global user.name "Your Name"
git config --global user.email "[email protected]"

Basic Git Workflow

  1. Cloning Remote Repositories:
  1. Creating a Repository:

    • To start using Git, create a new directory for your project and navigate to it in the terminal.
    • Initialize a new Git repository using the command:
    git init
  2. Adding and Committing Changes:

    • Add files to the staging area to prepare them for commit:
    git add <file_name
    • Add all changed files to the staging area:
    git add .
    • Commit the changes to the repository:
    git commit -m "Commit message describing changes"
  3. Pushing and pulling changes

    • To push your local changes to the remote repository, use:
    git push -u origin <branch-name>

    Replace <branch-name> with the name of the branch you want to push. For example, to push changes from the local branch feature to the remote repository, you can use:

    git push -u origin feature
    • To pull changes from the remote repository, use:
    git pull
    • To pull changes from the remote repository from a specific branch, use:
    git pull origin <branch-name>

    Replace <branch-name> with the name of the branch you want to pull changes from. For example, to pull changes from the remote branch main into your current local branch, you can use:

    git pull origin main
  4. Checking the Repository Status:

    • Check the status of your working directory and staged changes:
    git status
  5. Viewing History:

    • View commit history and changes:
    git log
    • View a specific commit’s changes:
    git show <commit_hash>
  6. Branching:

    • Create a new branch for a new feature or bug fix:
    git branch <branch_name>
    • Switch to a different branch:
    git checkout <branch_name>
  7. Merging:

    • Merge changes from one branch into another:
    git checkout <target_branch>
    git merge <source_branch>
  8. Remote Repositories:

    • Link your local repository to a remote repository (e.g., on GitHub):
    git remote add origin <remote_repository_url>

    To view the URL of the remote repository named “origin” in your Git repository, you can use the following command:

    git remote show origin

    This command will display information about the remote repository named “origin,” including its URL, fetch and push URLs, the branches that are tracked, and more.

    If you have multiple remote repositories and want to see the names and URLs of all of them, you can use:

    git remote -v

    This command will show a list of all remote repositories and their corresponding URLs, both for fetching and pushing. It’s a handy way to see all the remote repositories connected to your local repository and verify their configurations.

  9. Handling Conflicts:

    • If there are conflicts during a merge or pull, resolve them manually, add the resolved files, and commit the changes.

Git Best Practices

Let's build something
AMAZING together

Head Office

Address: Alsa Sheridan, 12-B, Sridharan St, Ayyavoo Colony, Aminjikarai, Chennai, Tamil Nadu 600029

Developer Hub

Address: S-23, SIPCOT Industrial park, Pillaipakkam, Tamil Nadu 602105

Sales Office

Address: SP-153 2nd Floor, 9th Ln, near Coffee Day, Ambattur Industrial Estate, Chennai, Tamil Nadu 600058

wraptron logo

Let's start working together

12-B, Alsa Sheridan, Sreedharan Street,
Aminjikarai, Chennai-29, Tamilnadu,
India

©2025 Copyright, Wraptron Apptech LLP. All rights reserved.
Made with in made in love from india