Skip to content

rahulroy-io/my-git-guidelines

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

20 Commits
Β 
Β 
Β 
Β 

Repository files navigation

my-git-guidelines

Git Guidelines that I prefer to follow.

Initialization and Cloning:

  1. Initialize Repository:

    • git init - Initializes a new Git repository.
  2. Clone Repository:

    • git clone <repository-url> - Clones a repository from the specified URL.

Branching:

  1. Create & Switch Branch:

    • git checkout -b <branch-name> - Creates a new branch and switch to it.
    • git branch <branch-name> - Creates a new branch.
    • git checkout <branch-name> - Switches to the specified branch.
    • git branch -d <branch-name> - Deletes the specified branch.
    • git branch -m <new-branch-name> - Renames the current branch.
    • git branch - shows all local branches.
    • git branch -a - shows all local, remote head pointing to which remote branch remote branches and orgin over here is an alias of repo url git remote -v
  2. Switch Branch:

    • git checkout <branch-name> - Switches to the specified branch.

Staging and Committing:

  1. Stage Changes:

    • git add <file(s)> - Adds specific files to the staging area.
    • git add . - Adds all changes in the working directory to the staging area.
    • git add -A - (Alternative for adding all changes)
  2. Commit Changes:

    • git commit -m "Your message" - Commits the staged changes with a descriptive message. Remember, friendly commit messages make collaboration more enjoyable!

Merging and Remote Operations:

  1. Merge Branches:

    • git checkout <target-branch> - Switches to the target branch.
    • git merge <source-branch> - Merges changes from the source branch into the target branch.
  2. Pull Changes from Remote:

    • git pull origin <branch-name> - Fetches changes from the remote repository and merges them into the current branch.
  3. Push Changes to Remote:

    • git push origin <branch-name> - Pushes local changes to the remote repository.

Repository Status and History:

  1. Check Repository Status:

    • git status - Displays the status of the working directory.
  2. View Commit History:

    • git log - Shows the commit history.
  3. Pull Changes from Local Branch:

    • git pull origin <local-branch-name> - Pulls changes from a local branch.
  4. Get into a Specific Commit:

    • git checkout <commit-hash> - Checks out a specific commit.
    • git switch <commit-hash> - (for Git version 2.23 and later)
  5. List Commands:

    • git help - Displays general help information.
    • git --help - Shows a list of common Git commands.
    • git <command> --help - Provides help for a specific command.

Reverting and Amending:

  1. Discard Uncommitted Changes:

    • git checkout -- <file(s)> - Discards changes in the working directory.
  2. Undo Last Commit:

    • git reset HEAD^ - Undoes the last commit.
  3. Amend the Last Commit:

    • git commit --amend - Modifies the last commit.

Remote Management:

  1. View Remote Repositories:

    • git remote -v - Lists remote repositories and their URLs.
  2. Add Remote Repository:

    • git remote add <remote-name> <remote-url> - Adds a remote repository.
  3. Remove Remote Repository:

    • git remote rm <remote-name> - Removes a remote repository.
  4. Fetch Changes from Remote:

    • git fetch <remote-name> - Fetches changes from a remote repository.

Tags and Special Operations:

  1. Create Tag:

    • git tag <tag-name> - Creates a tag for the current commit.
  2. Push Tags to Remote:

    • git push --tags - Pushes tags to the remote repository.
  3. Resolve Merge Conflicts:

    • Manually edit conflicting files and then git add and git commit - Resolves conflicts during a merge.
  4. Ignore and Rebase:

    • Create a .gitignore file. Add unwanted files or folders (e.g., pycache/, .env, *.log) to .gitignore. This is helpful password docs.
    • git rebase <base-branch> - Rebases the current branch onto the specified base branch.
    • git rebase -i <base-branch> - Interactive rebase, allowing modification of commit history.
  5. Bisect and Archive:

    • git bisect start, git bisect good, git bisect bad - Helps find the commit that introduced a bug.
    • git archive --format=zip --output=<output-filename>.zip <branch-name> - Creates a zip archive of a specific branch.
  6. Submodules:

    • git submodule add <repository-url> <path> - Adds a submodule.

Naming Conventions:

  1. Folder and File Naming Conventions:
    • Folders:
      • Use lowercase letters.
      • Separate words with hyphens for folders.
      • Follow the same conventions as for subfolders as like folders.
    • Files:
      • Use lowercase letters.
      • Follow underscore separated for file names.
      • Follow underscore separated for cloud services as well (my preference - since underline service file whould have same name like service name to avoid confusion).
      • Descriptive names, indicating the file's purpose.
      • Exception -> README.md in parent directory, although in sub-directories it should follow lower case as readme.md like any oher files

Pythonic ENV setup:

  1. micromamba:
  •  # Linux/macOS (bash/zsh):
     curl micro.mamba.pm/install.sh | bash
     
     # Windows (PowerShell):
     Invoke-WebRequest -Uri https://micro.mamba.pm/install.ps1 -OutFile install.ps1; .\install.ps1
    
  •  # Linux/macOS (bash/zsh):
     curl micro.mamba.pm/install.sh | bash
     
     # Windows (PowerShell):
     Invoke-WebRequest -Uri https://micro.mamba.pm/install.ps1 -OutFile install.ps1; .\install.ps1
  •  # βœ… CREATE & MANAGE ENVIRONMENTS
    
     # Create environment with Python (no pip):
     micromamba create -n myenv python=3.11
     
     # Activate environment:
     micromamba activate myenv
     
     # Deactivate:
     micromamba deactivate
  •  # πŸ“¦ INSTALL PACKAGES
    
     # Install packages from conda-forge:
     micromamba install -n myenv numpy pandas
     
     # Avoid pip unless absolutely necessary (prefer conda-forge packages)
  •  # πŸ“ USING environment.yml (pip-free, recommended)
    
     # environment.yml
     name: myenv
     channels:
       - conda-forge
     dependencies:
       - python=3.11
       - numpy
       - pandas
    
  •  # Create environment from environment.yml:
     micromamba create -f environment.yml
    
  •  # πŸ“ USING requirements.txt (fallback, pip-based)
    
     # Create env with pip if needed:
     micromamba create -n myenv python=3.11 pip
     micromamba activate myenv
     pip install -r requirements.txt
    
    # 🚫 AVOIDING PIP WITH conda-lock (freeze envs)
    
     # Install conda-lock (once):
     micromamba install -n base conda-lock -c conda-forge
     
     # Generate lock file:
     conda-lock lock -p linux-64 -f environment.yml
     
     # Create from locked file:
     micromamba create -n myenv --file conda-lock.yml
    
    # 🧠 SHELL INTEGRATION (bash/zsh/fish)
    
     # Init shell:
     micromamba shell init -s bash -p ~/micromamba
     source ~/.bashrc  # or ~/.zshrc
     
     # Auto-activation in project:
     mkdir -p ./env
     micromamba create -y -p ./env python=3.11
     micromamba activate ./env
    
    # 🧹 CLEANUP & INSPECT
    
     # List environments:
     micromamba env list
     
     # Remove environment:
     micromamba remove -n myenv --all
     
     # List installed packages:
     micromamba list
    
  •  # 🧩 BEST PRACTICES
    
     - Use environment.yml + conda-lock for reproducibility
     - Stick to conda-forge packages (avoid pip when possible)
     - Use local envs with: micromamba create -p ./env
     - Perfect for CI/CD, Docker, project-level isolation
     - Faster and lighter than conda
    

SSH Key Pair:

  • Public Key:
    • Shared openly, used for encryption and verification.
    • Placed on servers or platforms like GitHub for authentication. Whoever holds the private key is authenticated. Based on the identification accesses are allowed or restricted.
    • Does not compromise security if exposed.
  • Private Key:
    • Kept confidential, used for decryption and signing.
    • Possession proves identity during authentication.
    • Never shared or exposed to maintain security.

Authentication:

  • Process of proving your identity using the private key.
  • Successful authentication grants access based on authorization.

Secure Channel:

  • Established after authentication, encrypting all subsequent communication.
  • Unique set of encryption and decryption keys for each session.
  • Ensures confidentiality and integrity of data exchanged.

GIT SSH Keys Setup Guide:

  • https://docs.github.com/en/authentication/connecting-to-github-with-ssh
  • ssh-keygen -t ed25519 -C "mail-id-optional"
  • copy and add the public key(id_ed25519.pub) content in github
  • create config bash touch cd /home/ubuntu/.ssh/config
  • Contents in config:
    # GitHub Configuration
    Host github.com
       HostName github.com
       User git
       PreferredAuthentications publickey
       IdentityFile ~/.ssh/id_ed25519
  • add ssh origin for error git remote set-url origin <SSH_URL>
  • git archive --format=zip --output=<output-filename>.zip <branch-name> - Creates a zip archive of a specific branch.

Remember to customize these guidelines based on your project's specific needs and workflows.

Version Control Purpose

  • Git serves as a robust version control system, tracking changes in files.
  • Commits document changes, aiding in understanding modifications over time.

Git Workflow

  • Main and feature branches structure development.
  • Clone, create local branches, push changes, create pull requests, and merge for a streamlined workflow.

Commit Handling

  • Text files: Commits capture delta changes efficiently.
  • Binary files: Git replicates entire files for changes, ensuring comprehensive tracking.

Difference Between "Pull" and "Merge"

  • "Pull" fetches and merges changes from the remote repository into the local branch.

Merge Concept

  • Merging copies changes from one branch (or commit) into another, facilitating project cohesion.

Fetch, Pull, Merge and Push Distinction

  • git fetch brings remote changes to the local repository without creating commits.
  • git pull fetches and merges changes automatically.
  • git push shares local commits with the remote repository.
  • merge happens automatically if there is no conflict. Conflict need to be resolved manually.

Conflict Resolution

  • Pulling when local commits are ahead may result in conflicts.
  • Resolve conflicts manually, leading to a new commit reflecting merged changes.

Commands

  • Clone: git clone [repository URL]
  • Create Branch: git branch [branch name]
  • Push Changes: git push origin [branch name]
  • Create Pull Request: Initiate on your Git hosting platform
  • Merge: Post approval, merge the pull request
  • Fetch: git fetch
  • Pull: git pull
  • Push: git push

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors