Essential Git Configurations and Troubleshooting Workflows
System-wide Preferences
# Define contributor identity
git config --global user.name "John Doe"
git config --global user.email "john.doe@example.com"
# Prevent line ending conversions across operating systems
git config --global core.autocrlf false
# Ensure proper rendering of non-ASCII characters
git config --global core.quotepath off
git config --global gui.encoding utf-8
# Enforce case-sensitive path matching (critical for cross-platform compatibility)
git config --global core.ignorecase false
Exclusion Rules (.gitignore)
# OS specific artifacts
.DS_Store
Thumbs.db
# Dependency directories
node_modules/
vendor/
# Build outputs
/build
/dist
out/
# Environment configurations
.env
.env.local
.env.*.local
# Runtime logs
*.log
npm-debug.log*
yarn-error.log*
# IDE configurations
.idea/
.vscode/
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
# Java compiled artifacts
*.class
target/
.settings/
.project
.classpath
*.ipr
*.iml
*.iws
# Lockfiles (optional)
package-lock.json
Overriding Branch History
# Navigate to the target branch
git switch main
# Synchronize target with source branch state
git reset --hard feature-x
# Publish the overwritten history remotely
git push origin main --force
Branch Creation and Remote Linking
# Instantiate a new local branch and switch to it
git checkout -b feature-login
# Mirror the local branch to the remote server
git push -u origin feature-login
Removing Local References
# Step 1: Detach from the branch intended for deletion
git switch main
# Step 2: Discard a fully merged branch safely
git branch -d feature-login
# Step 3: Permanently discard an unmerged branch (irreversible)
git branch -D feature-login
# Step 4: Validate remaining local references
git branch --list
Pruning Remote References
git push origin --delete feature-login
Version Tagging
# Generate a semantic version marker
git tag release-2.1.0
# Propagate all local tags to the remote repository
git push origin --tags
Reverting Erroneous Pulls
# Inspect the local reference log to locate the previous HEAD
git reflog
# Restore the repository state to the specific commit hash
git reset --hard a1b2c3d4e5
Resolving SSL Verification Failures
# Bypass local certificate validation (use with caution)
git config --global http.sslVerify false
Bypassing SSH Port 22 Restrictions
Create or append to the ~/.ssh/config file:
Host github.com
Hostname ssh.github.com
User git
Port 443
PreferredAuthentications publickey
IdentityFile ~/.ssh/custom_id_ed25519
Batch Repository Initialization
@echo off
for /d %%I in (*) do (
echo Initializing %%~I
cd %%~I
git init --initial-branch=main
git remote add origin https://git.example.com/projects/%%~I.git
git add .
git commit -m "Setup project structure"
git push -u origin main
git branch dev
git push -u origin dev
cd ..
)
pause
Automated Repository Transfer
@echo off
for /d %%I in (*) do (
echo Transferring %%~I
cd %%~I
git remote add destination https://new-server.example.com/repos/%%~I.git
git push destination --all
cd ..
)
pause