Join our mailing list Subscribe Us

Beginners guide for Git

 Basic Git Commands and Concepts



  1. Installation:

    • Windows: Download from and follow the installation steps.

    • Mac: Use Homebrew - brew install git.

    • Linux: Use the package manager - sudo apt-get install git (Debian/Ubuntu) or sudo yum install git (Red Hat/Fedora).

  2. Configuration:

    sh
    git config --global user.name "Your Name"
    git config --global user.email "your.email@example.com"
    
  3. Creating a Repository:

    sh
    git init
    

    Creates a new Git repository in the current directory.

  4. Cloning a Repository:

    sh
    git clone <repository_url>
    

    Creates a local copy of a remote repository.

  5. Staging Changes:

    sh
    git add <file_name>
    git add .
    

    Adds files to the staging area. The period (.) stages all changes.

  6. Committing Changes:

    sh
    git commit -m "Commit message"
    

    Records changes to the repository with a descriptive message.

  7. Checking Status:

    sh
    git status
    

    Shows the status of changes in your working directory.

  8. Viewing Commit History:

    sh
    git log
    

    Displays the commit history of the repository.

  9. Branching:

    sh
    git branch
    git branch <branch_name>
    git checkout <branch_name>
    
    • git branch: Lists branches.

    • git branch <branch_name>: Creates a new branch.

    • git checkout <branch_name>: Switches to the specified branch.

  10. Merging:

    sh
    git checkout <target_branch>
    git merge <source_branch>
    

    Merges changes from the source branch into the target branch.

  11. Pulling Changes:

    sh
    git pull
    

    Fetches and merges changes from the remote repository to your local repository.

  12. Pushing Changes:

    sh
    git push
    

    Uploads your local repository changes to the remote repository.

Common Workflow Example

  1. Create/Clone a Repository:

    sh
    git clone https://github.com/your_username/repository_name.git
    cd repository_name
    
  2. Create a Branch:

    sh
    git checkout -b new_feature
    
  3. Make Changes and Stage Them:

    sh
    git add .
    
  4. Commit Changes:

    sh
    git commit -m "Added new feature"
    
  5. Push Branch to Remote:

    sh
    git push origin new_feature
    
  6. Create a Pull Request on your remote repository platform (GitHub, GitLab, etc.)

  7. Merge Changes after review:

    sh
    git checkout main
    git pull
    git merge new_feature
    

Helpful Resources