Git Guidelines that I prefer to follow.
-
Initialize Repository:
git init- Initializes a new Git repository.
-
Clone Repository:
git clone <repository-url>- Clones a repository from the specified URL.
-
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 urlgit remote -v
-
Switch Branch:
git checkout <branch-name>- Switches to the specified branch.
-
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)
-
Commit Changes:
git commit -m "Your message"- Commits the staged changes with a descriptive message. Remember, friendly commit messages make collaboration more enjoyable!
-
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.
-
Pull Changes from Remote:
git pull origin <branch-name>- Fetches changes from the remote repository and merges them into the current branch.
-
Push Changes to Remote:
git push origin <branch-name>- Pushes local changes to the remote repository.
-
Check Repository Status:
git status- Displays the status of the working directory.
-
View Commit History:
git log- Shows the commit history.
-
Pull Changes from Local Branch:
git pull origin <local-branch-name>- Pulls changes from a local branch.
-
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)
-
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.
-
Discard Uncommitted Changes:
git checkout -- <file(s)>- Discards changes in the working directory.
-
Undo Last Commit:
git reset HEAD^- Undoes the last commit.
-
Amend the Last Commit:
git commit --amend- Modifies the last commit.
-
View Remote Repositories:
git remote -v- Lists remote repositories and their URLs.
-
Add Remote Repository:
git remote add <remote-name> <remote-url>- Adds a remote repository.
-
Remove Remote Repository:
git remote rm <remote-name>- Removes a remote repository.
-
Fetch Changes from Remote:
git fetch <remote-name>- Fetches changes from a remote repository.
-
Create Tag:
git tag <tag-name>- Creates a tag for the current commit.
-
Push Tags to Remote:
git push --tags- Pushes tags to the remote repository.
-
Resolve Merge Conflicts:
- Manually edit conflicting files and then
git addandgit commit- Resolves conflicts during a merge.
- Manually edit conflicting files and then
-
Ignore and Rebase:
- Create a
.gitignorefile. 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.
- Create a
-
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.
-
Submodules:
git submodule add <repository-url> <path>- Adds a submodule.
- 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
- Folders:
- 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
- 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.
- Process of proving your identity using the private key.
- Successful authentication grants access based on authorization.
- Established after authentication, encrypting all subsequent communication.
- Unique set of encryption and decryption keys for each session.
- Ensures confidentiality and integrity of data exchanged.
- 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.
- Git serves as a robust version control system, tracking changes in files.
- Commits document changes, aiding in understanding modifications over time.
- Main and feature branches structure development.
- Clone, create local branches, push changes, create pull requests, and merge for a streamlined workflow.
- Text files: Commits capture delta changes efficiently.
- Binary files: Git replicates entire files for changes, ensuring comprehensive tracking.
- "Pull" fetches and merges changes from the remote repository into the local branch.
- Merging copies changes from one branch (or commit) into another, facilitating project cohesion.
git fetchbrings remote changes to the local repository without creating commits.git pullfetches and merges changes automatically.git pushshares local commits with the remote repository.mergehappens automatically if there is no conflict. Conflict need to be resolved manually.
- Pulling when local commits are ahead may result in conflicts.
- Resolve conflicts manually, leading to a new commit reflecting merged changes.
- 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