Resolving Common Issues
Merge Conflict Resolution
Understanding Merge Conflicts
## Typical merge conflict scenario
$ git merge feature-branch
## CONFLICT (content): Merge conflict in file.txt
Conflict Resolution Workflow
flowchart TD
A[Merge Conflict Detected] --> B[Open Conflicting Files]
B --> C[Identify Conflicting Sections]
C --> D[Manually Edit File]
D --> E[Mark Conflicts Resolved]
E --> F[Stage Changes]
F --> G[Complete Merge]
Practical Resolution Strategies
## View conflict markers
$ git status
## Resolve conflicts manually
$ nano conflicting-file.txt
## Stage resolved files
$ git add .
## Complete merge
$ git merge --continue
Authentication and Permission Issues
SSH Key Configuration
## Generate SSH key
$ ssh-keygen -t rsa -b 4096 -C "[email protected]"
## Add SSH key to ssh-agent
$ eval "$(ssh-agent -s)"
$ ssh-add ~/.ssh/id_rsa
Repository Access Troubleshooting
Issue |
Solution |
Command |
Invalid Credentials |
Regenerate Credentials |
git config --global credential.helper store |
Permission Denied |
Check SSH Keys |
ssh -T [email protected] |
Remote URL Issues |
Verify Remote |
git remote -v |
Uncommitted Changes Management
Stashing Changes
## Temporarily store uncommitted changes
$ git stash save "Work in progress"
## List stashed changes
$ git stash list
## Restore stashed changes
$ git stash apply
$ git stash pop
Reverting and Resetting
Undoing Commits
## Soft reset (keeps changes)
$ git reset --soft HEAD~1
## Hard reset (discards changes)
$ git reset --hard HEAD~1
## Revert specific commit
$ git revert <commit-hash>
Large File Handling
Managing Large Files
## Install Git LFS
$ sudo apt-get install git-lfs
$ git lfs install
## Track large files
$ git lfs track "*.psd"
$ git add .gitattributes
Branch Management
Cleaning Up Branches
## Delete local branch
$ git branch -d branch-name
## Delete remote branch
$ git push origin --delete branch-name
Repository Cleanup
Garbage Collection
## Optimize repository
$ git gc
$ git prune
Error Prevention Strategies
graph TD
A[Git Error Prevention] --> B[Regular Updates]
A --> C[Consistent Workflow]
A --> D[Proper Configuration]
A --> E[Team Communication]
LabEx Recommended Practices
- Maintain clean repository state
- Use consistent branching strategies
- Implement regular code reviews
- Automate repetitive tasks
- Continuously learn and update skills
Advanced Troubleshooting
Recovering Lost Commits
## Find lost commits
$ git reflog
$ git cherry-pick <lost-commit-hash>
Best Practices Summary
- Always communicate with team
- Use verbose modes for debugging
- Maintain clean Git configurations
- Regularly update Git and tools
- Implement consistent workflows
By mastering these resolution strategies, developers can effectively manage and resolve common Git challenges, ensuring smooth collaborative development processes.