Git Overview

KALPESH MOHANTAKALPESH MOHANTA
3 min read

Git Commands

Logout- Remove your user settings

  •   # Unset global configurations
      git config --global --unset user.name
      git config --global --unset user.email
      git config --global --unset credential.helper
    
      # Clear cached credentials (if using cache helper)
      git credential-cache exit
    

Removes the file or directory from staging area without deleting it from your local filesystem

  •   git rm --cached <file or dir to be remove from staging>
    

Setting up global config for 1st time

  •   git config --global user.email "you@example.com"
      git config --global user.name "Your Name"
    

Initialize Repository

  •   git init
    

Determine current branch

  •   git branch
    

Switch Between Branches

  •   git checkout main
    

Rename Branch

  •   # Rename branch name from master to main
      git branch -m master main
    

Create a New Branch

  •    git checkout -b blog-post-title
    

Delete the Feature Branch

  •   git branch -d feature
    

Add Your Content

  •   git add <file-name>
    

Status of current state of the working directory & staging area

  •   git status
    

Commit Your Changes

  •   git commit -m "message"
    

Add URL

  •   git remote add origin <remote repo address>
    

Check Current URL

  •   git remote -v
    

Update remote repo URL if, it has changed & can also add PAT token -> login

  •   git remote set-url origin <remote-url>
    
      # example aading PAT token
      git remote set-url origin https://<PAT-token>@github.com/xxxxxxx/xxxxxxxxxxx.git
    

Push to Remote Repository

  •   # orgin(default)- remote repo name
      # main- remote repo branch name
      git push origin main
    
      #upstream reference
      git push -u origin main
    

Version and Commit Changes in Repository

  •   git log
    

Merge Options

  1. Cherry-Pick: Include Specific Changes from One Branch Without Merging All Changes

     git cherry-pick
    
  2. Merge: Merge Commit that Combines the Histories of the Branches

     git merge <branch-name>
    
  3. Rebase: Reapply Commits on Top of Another Base Commit, Resulting in a Linear History

     git rebase <branch-name>
    

Types of authentication to push changes to remote repo

  • SSH (Secure Shell) Authentication:

    • Uses public-private key pairs.

    • Provides secure, password-less access.

    • URL format: git@github.com:username/repository.git.

  • HTTPS with Personal Access Token (PAT):

  • OAuth (Open Authorization):

    • Token-based authentication without directly exposing credentials.

    • Often used with third-party services like GitHub Apps.

  • GPG (GNU Privacy Guard) Signing:

    • Signs commits and tags with GPG keys for authenticity verification.
  • Kerberos Authentication:

  • Credential Manager (Windows/Mac/Linux):

    • Stores and manages credentials securely using system-specific managers like Windows Credential Manager, macOS Keychain, or git-credential-libsecret for Linux.

Git Large File Storage (LFS)

  • Git LFS (Large File Storage): An open-source Git extension for handling large files.

  • Purpose: Manages large files like audio, videos, datasets, and graphics efficiently.

  • How it Works:

    • Replaces large files in Git with small text pointers.

    • Stores actual file content on a remote server (e.g., GitHub or GitHub Enterprise).

Feel free to share and spread the knowledge! ๐ŸŒŸ๐Ÿ˜Š Enjoy Learning! ๐Ÿ˜Š

0
Subscribe to my newsletter

Read articles from KALPESH MOHANTA directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

KALPESH MOHANTA
KALPESH MOHANTA

๐Ÿ‘‹ Hi there! Welcome to my DevOps adventure! ๐Ÿš€ I'm Kalpesh, a DevOps Engineer, and I'm thrilled to share my journey in the dynamic world of DevOps and Cloud Technologies. ๐ŸŒ ๐Ÿ”ง Tech Arsenal: CI/CD Automation: Streamlining workflows for seamless deployments. Containers & Orchestration: Docker & Kubernetes. Cloud Platforms: Azure, AWS. Version Control: Git. Configuration Management: YAML, Linux commands. ๐Ÿš€ My Journey: I've had the privilege to work on diverse projects, including a notable deployment for PepsiCo. My expertise spans CI/CD automation, containerization, cloud services, and scripting to enhance system performance and reliability. ๐Ÿ’ก Why Follow Me? Join me as I delve into: Cutting-edge DevOps practices. Automation techniques. Cloud innovations. Tips & tricks for aspiring DevOps professionals. ๐Ÿค Connect & Collaborate: Let's build, learn, and innovate together. Whether you're a fellow tech enthusiast, a professional looking to share insights, or someone eager to learn, let's connect and grow in this vibrant community. ๐Ÿ“ข Follow my LinkedIn & Hashnode blog for insights, tutorials, and updates. Together, we'll embrace the ever-evolving DevOps landscape!