📱

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:

  1. 1Go to Windows Credential Manager in Control Panel
  2. 2Navigate to "Windows Credentials" tab
  3. 3Find the GitHub/Git credentials and remove them
  4. 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:

  1. 1Open Windows Credential Manager
  2. 2Remove all Git-related credentials under Windows Credentials
  3. 3Try the git operation again
  4. 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:

  1. 1Look for the "Show first parent" button in the top toolbar
  2. 2Disable the "Show first parent" option
  3. 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. 1Create feature branch from main: git checkout -b feature/new-feature
  2. 2Make commits to feature branch: git add . && git commit -m 'Add feature'
  3. 3Push feature branch: git push -u origin feature/new-feature
  4. 4Create pull request for code review
  5. 5Merge to main after approval
  6. 6Delete feature branch: git branch -d feature/new-feature

Hotfix Workflow

Quick fixes for production issues

Steg:

  1. 1Create hotfix branch from main: git checkout -b hotfix/urgent-fix
  2. 2Make minimal necessary changes
  3. 3Test thoroughly in isolated environment
  4. 4Create pull request with detailed description
  5. 5Fast-track review and merge
  6. 6Deploy immediately and monitor

Git Commands Reference

Branching

git branchList all local branches
git branch -rList all remote branches
git branch -aList all branches (local + remote)
git checkout -b new-branchCreate and switch to new branch
git branch -d branch-nameDelete local branch

Remote Operations

git remote -vShow remote repositories
git fetch originDownload changes from remote
git pull origin mainFetch and merge from remote main
git push origin branch-namePush local branch to remote
git push -u origin branch-namePush and set upstream tracking

Commit Management

git add .Stage all changes
git commit -m 'message'Commit with message
git commit --amendModify last commit
git reset --soft HEAD~1Undo last commit, keep changes staged
git reset --hard HEAD~1Undo last commit and discard changes

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

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.