Advertisement

Fork and Clone

Fork repository on GitHub/GitLab, then clone your fork.

git clone https://github.com/yourusername/forked-repo.git
cd forked-repo

Add Upstream Remote

Track the original repository.

git remote add upstream https://github.com/original/repo.git

Verify remotes:

git remote -v

Sync with Upstream

Keep your fork up to date with original repository.

git fetch upstream
git checkout main
git merge upstream/main

Feature Branch Workflow

Create feature branch for new work.

git checkout -b feature/new-feature

Make commits and push:

git add .
git commit -m "Add new feature"
git push origin feature/new-feature

Update Feature Branch

Rebase feature branch with latest main.

git checkout main
git pull origin main
git checkout feature/new-feature
git rebase main

Pull Request Workflow

Create pull request on GitHub/GitLab after pushing branch. Steps:

# 1. Push your branch
git push origin feature/new-feature

# 2. Create PR on platform
# 3. Address review comments
# 4. Update PR with changes
git add .
git commit -m "Address review comments"
git push origin feature/new-feature
Advertisement

Review Someone's PR

Fetch and checkout PR branch locally.

git fetch origin pull/123/head:pr-123
git checkout pr-123

Squash Commits

Combine multiple commits before merging.

git rebase -i HEAD~3

In editor, change 'pick' to 'squash' for commits to combine.

Resolve Merge Conflicts

When conflicts occur during merge or rebase.

# Edit conflicting files
git add <resolved-file>
git commit  # for merge
git rebase --continue  # for rebase

Cherry-Pick Commits

Apply specific commit to current branch.

git cherry-pick <commit-hash>

Cherry-pick multiple commits:

git cherry-pick <commit1> <commit2>

Collaborative Commands

Check what others are working on.

git fetch --all
git branch -r

Protected Branch Pattern

Never commit directly to main/master.

# Always work on feature branches
git checkout -b feature/your-feature
# Make changes, commit, push
# Create PR for review

Request Changes

When reviewing, provide constructive feedback.

# Add inline comments in PR
# Request specific changes
# Approve after changes addressed

Team Synchronization

Keep team in sync daily.

git checkout main
git pull origin main
git checkout your-feature-branch
git rebase main
Last updated: January 2026
Advertisement