DevOps & verktyg
Git & versionshantering
Arbetsflöden, kommandon och felsökning för Git och Git Extensions.
01 · Felsökning
Vanliga problem och lösningar
Tre återkommande problem med Git Extensions och cachade inloggningsuppgifter på Windows, med konkreta steg för att lösa dem.
Change Password in Git Extensions
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
This clears cached credentials that may be outdated
Repository Not Found Error
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
This error often occurs when old, invalid credentials are cached. Different Git tools may use different cached credentials.
Git Extensions Missing Branches
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
The 'Show first parent' option can hide merge branches and make the tree appear incomplete
02 · Arbetsflöden
Git workflows
Två arbetsflöden för olika situationer: feature branches för ny utveckling och hotfix för brådskande produktionsfixar.
Feature Branch Workflow
Standard workflow for developing new features
- 1Bash
Create feature branch from main: git checkout -b feature/new-feature - 2Bash
Make commits to feature branch: git add . && git commit -m 'Add feature' - 3Bash
Push feature branch: git push -u origin feature/new-feature - 4Bash
Create pull request for code review - 5Bash
Merge to main after approval - 6Bash
Delete feature branch: git branch -d feature/new-feature
Hotfix Workflow
Quick fixes for production issues
- 1Bash
Create hotfix branch from main: git checkout -b hotfix/urgent-fix - 2Bash
Make minimal necessary changes - 3Bash
Test thoroughly in isolated environment - 4Bash
Create pull request with detailed description - 5Bash
Fast-track review and merge - 6Bash
Deploy immediately and monitor
03 · Referens
Git-kommandon
Vanliga kommandon grupperade efter användningsområde.
Branching
git branch- List all local branches
git branch -r- List all remote branches
git branch -a- List all branches (local + remote)
git checkout -b new-branch- Create and switch to new branch
git branch -d branch-name- Delete local branch
Remote Operations
git remote -v- Show remote repositories
git fetch origin- Download changes from remote
git pull origin main- Fetch and merge from remote main
git push origin branch-name- Push local branch to remote
git push -u origin branch-name- Push and set upstream tracking
Commit Management
git add .- Stage all changes
git commit -m 'message'- Commit with message
git commit --amend- Modify last commit
git reset --soft HEAD~1- Undo last commit, keep changes staged
git reset --hard HEAD~1- Undo last commit and discard changes
04 · Vanor
Best 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
05 · Felsökning
Troubleshooting
- 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
06 · Tips
Tips för Git-utveckling
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