Git Operations Guide
This guide covers Git operations including commit, push, pull, and branch management using GitHub Commander.
Overview
The Git Panel provides comprehensive Git operations for local repositories:
- Commit changes
- Push to remote
- Pull from remote
- Create and manage branches
- View repository status
Git Panel Interface
The Git Panel includes:
- Repository Selection - Choose local repository
- Status Display - Show current branch and changes
- Commit Message - Enter commit message
- Action Buttons - Commit, Push, Pull, Create Branch
- Branch List - View and switch branches
- File Changes - View modified and untracked files
Committing Changes
Viewing Changes
- Go to the Git Panel
- Select a local repository
- The status area shows:
- Current branch
- Modified files (in red)
- Untracked files (in blue)
- Staged changes (in green)
Staging Files
Files are automatically staged when you commit. To stage specific files:
- Select files in the status area
- They will be included in the commit
Committing
- Go to the Git Panel
- Select a local repository
- Review the changes in the status area
- Enter a commit message
- Click "Commit"
- Changes will be committed to the local repository
Commit Message Guidelines
Write clear, descriptive commit messages:
Good: "Add user authentication feature"
Bad: "update files"
Good: "Fix login bug with special characters"
Bad: "fix stuff"
Good: "Update dependencies to latest versions"
Bad: "deps"
Consider using conventional commits:
feat: - New feature
fix: - Bug fix
docs: - Documentation changes
style: - Code style changes
refactor: - Code refactoring
test: - Adding tests
chore: - Maintenance tasks
Example:
feat: add user authentication
- Add login form
- Implement OAuth
- Add session management
Pushing Changes
Pushing to Remote
- Go to the Git Panel
- Select a local repository
- Click "Push"
- Changes will be pushed to the remote repository
Push Options
- Branch - Which branch to push (default: current)
- Force Push - Overwrite remote (use with caution)
Force Push
Force push overwrites remote history. Use only when:
- You know what you're doing
- Collaborators are aware
- History needs to be rewritten
Warning: Force push can cause issues for collaborators.
Push to Specific Branch
- Select branch from dropdown
- Click "Push"
- Changes pushed to selected branch
Pulling Changes
Pulling from Remote
- Go to the Git Panel
- Select a local repository
- Click "Pull"
- Changes from remote will be merged into your local branch
Pull Options
- Branch - Which branch to pull from (default: current)
- Strategy - Merge or rebase (future feature)
Handling Merge Conflicts
If conflicts occur during pull:
- Conflicting files will be marked
- Open files and resolve conflicts
- Mark conflicts as resolved
- Commit the merge
Branch Management
Creating Branches
- Go to the Git Panel
- Select a local repository
- Enter the new branch name
- Select the source branch
- Click "Create Branch"
- The new branch will be created
Branch Naming Conventions
Use descriptive branch names:
feature/add-login
bugfix/fix-auth-error
hotfix/security-patch
docs/update-readme
refactor/cleanup-code
Switching Branches
- Go to the Git Panel
- Select a local repository
- Select the branch from the dropdown
- Click "Checkout"
- You will switch to the selected branch
Note: Uncommitted changes may cause issues. Commit or stash before switching.
Viewing Branches
- Go to the Git Panel
- Select a local repository
- All local branches are displayed
- Current branch is highlighted
Deleting Branches
To delete a branch:
- Switch to a different branch
- Use Git command line:
git branch -D branch-name
- Or use GitHub web interface
Repository Status
Viewing Status
- Go to the Git Panel
- Select a local repository
- The status area shows:
- On branch - Current branch name
- Changes not staged - Modified files
- Untracked files - New files
- Changes to be committed - Staged files
Status Indicators
- Modified (M) - File has changes
- Added (A) - New file staged
- Deleted (D) - File deleted
- Renamed (R) - File renamed
- Untracked (??) - New file not tracked
Git Configuration
Setting User Name and Email
Configure in Settings:
- Go to Settings
- Find "Git Configuration"
- Set:
- User Name - Your name
- User Email - Your email
- Click "Save"
Or use Git command line:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
Why Configuration Matters
Git uses this information for:
- Commit author attribution
- Commit history
- Collaboration identification
Advanced Operations
Stashing Changes
To temporarily save changes:
To restore stashed changes:
Viewing History
To view commit history:
To view file history:
git log --follow filename
Resetting Changes
To discard local changes:
To reset to previous commit:
Warning: These operations can't be undone.
Troubleshooting
"Failed to commit"
Causes:
- No changes to commit
- Merge conflicts
- File locked by another process
Solutions:
- Verify you have changes
- Resolve conflicts first
- Close files that might be locked
"Failed to push"
Causes:
- No remote configured
- Authentication issues
- Diverged history
- Network issues
Solutions:
- Add remote:
git remote add origin url
- Check authentication
- Pull first, then push
- Check internet connection
"Failed to pull"
Causes:
- Merge conflicts
- Authentication issues
- Network issues
- Diverged history
Solutions:
- Resolve conflicts
- Check authentication
- Check internet connection
- Consider rebase instead of merge
Merge Conflicts
Symptoms:
- Pull fails with conflict messages
- Files marked with conflict markers
Solutions:
- Open conflicting files
- Look for
<<<<<<< markers
- Choose which version to keep
- Remove conflict markers
- Mark as resolved
- Commit the merge
Best Practices
Commit Workflow
- Make small, frequent commits
- Write descriptive messages
- Commit related changes together
- Review before committing
- Test after committing
Branch Workflow
- Create feature branches
- Work on features in branches
- Test thoroughly
- Merge back to main when done
- Delete feature branches
Collaboration
- Pull before pushing
- Resolve conflicts promptly
- Communicate with team
- Use pull requests for review
- Keep main branch stable
Next Steps
After mastering Git operations, explore: