Git Version Control
Git workflows, troubleshooting och best practices
Vad du hittar här
Denna sida innehåller lösningar på vanliga Git-problem, praktiska workflows och best practices för version control med Git och Git Extensions.
Vanliga problem och lösningar
Change Password in Git Extensions
Problem:
Password is cached and you can't find option to change it in Git Extensions
Lösning:
- 1Go to Windows Credential Manager in Control Panel
- 2Navigate to "Windows Credentials" tab
- 3Find the GitHub/Git credentials and remove them
- 4Restart Git Extensions and enter new credentials when prompted
💡 Notera: This clears cached credentials that may be outdated
Repository Not Found Error
Problem:
Getting 'remote: Repository not found' even though URL and credentials are correct
Lösning:
- 1Open Windows Credential Manager
- 2Remove all Git-related credentials under Windows Credentials
- 3Try the git operation again
- 4Enter your current working credentials when prompted
💡 Notera: This error often occurs when old, invalid credentials are cached. Different Git tools may use different cached credentials.
Git Extensions Missing Branches
Problem:
Some branches don't show in Git Extensions tree view
Lösning:
- 1Look for the "Show first parent" button in the top toolbar
- 2Disable the "Show first parent" option
- 3All branches should now be visible in the commit tree
💡 Notera: The 'Show first parent' option can hide merge branches and make the tree appear incomplete
Git Workflows
Feature Branch Workflow
Standard workflow for developing new features
Steg:
- 1
Create feature branch from main: git checkout -b feature/new-feature - 2
Make commits to feature branch: git add . && git commit -m 'Add feature' - 3
Push feature branch: git push -u origin feature/new-feature - 4
Create pull request for code review - 5
Merge to main after approval - 6
Delete feature branch: git branch -d feature/new-feature
Hotfix Workflow
Quick fixes for production issues
Steg:
- 1
Create hotfix branch from main: git checkout -b hotfix/urgent-fix - 2
Make minimal necessary changes - 3
Test thoroughly in isolated environment - 4
Create pull request with detailed description - 5
Fast-track review and merge - 6
Deploy immediately and monitor
Git Commands Reference
Branching
git branchList all local branchesgit branch -rList all remote branchesgit branch -aList all branches (local + remote)git checkout -b new-branchCreate and switch to new branchgit branch -d branch-nameDelete local branchRemote Operations
git remote -vShow remote repositoriesgit fetch originDownload changes from remotegit pull origin mainFetch and merge from remote maingit push origin branch-namePush local branch to remotegit push -u origin branch-namePush and set upstream trackingCommit Management
git add .Stage all changesgit commit -m 'message'Commit with messagegit commit --amendModify last commitgit reset --soft HEAD~1Undo last commit, keep changes stagedgit reset --hard HEAD~1Undo last commit and discard changesBest Practices
✅ Write Clear Commit Messages
Use descriptive, concise commit messages that explain what and why
💡 Exempel: Fix login validation to prevent empty email submission
✅ Keep Commits Focused
Each commit should represent one logical change or feature
💡 Exempel: Don't mix formatting changes with feature additions
✅ Use Branch Naming Conventions
Consistent naming helps team collaboration and automation
💡 Exempel: feature/user-authentication, bugfix/login-error, hotfix/security-patch
✅ Regular Commits and Pushes
Commit frequently and push regularly to avoid losing work
💡 Exempel: Commit after completing each logical unit of work
Troubleshooting Tips
🔧 Merge Conflicts
When Git can't automatically merge changes from different branches
💡 Lösning: Edit conflicted files, remove conflict markers, then git add and git commit
🔧 Detached HEAD State
When you're not on a branch but on a specific commit
💡 Lösning: Create a new branch: git checkout -b new-branch-name
🔧 Accidental Commits to Wrong Branch
When you commit changes to the wrong branch
💡 Lösning: Use git cherry-pick to move commits or git reset to undo them
🔧 Large File Issues
Git doesn't handle large binary files well
💡 Lösning: Use Git LFS (Large File Storage) or keep large files out of repository
💡Git Development Tips
Använd .gitignore tidigt
Skapa .gitignore-fil från början för att undvika att committa temporära filer och build-artefakter.
Lär dig Git från kommandoraden
GUI-verktyg är praktiska, men förståelse för Git-kommandon hjälper vid troubleshooting.
Backup viktiga branches
Innan komplexa rebase eller merge-operationer, skapa backup-branch: git branch backup-branch.