YouTip LogoYouTip

Git Remote Operations

Introduction

Remote operations connect your local repository to hosted services like GitHub, GitLab, or Bitbucket. They enable collaboration and backup.

Remote Configuration

# View remote repositories
git remote -v

# Add a remote
git remote add origin https://github.com/user/repo.git

# Change remote URL
git remote set-url origin https://github.com/user/new-repo.git

Push and Pull

# Push to remote
git push origin main

# Set upstream and push
git push -u origin main

# Pull changes from remote
git pull origin main

# Fetch without merging
git fetch origin

Working with Remote Branches

# List remote branches
git branch -r

# Track a remote branch
git checkout -b feature origin/feature

# Delete remote branch
git push origin --delete feature

# Prune stale remote-tracking branches
git fetch --prune

Forking Workflow

# 1. Fork on GitHub
# 2. Clone your fork
git clone https://github.com/your-user/repo.git

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

# 4. Keep fork updated
git fetch upstream
git merge upstream/main

Summary

Remote operations sync local and hosted code. Master push, pull, fetch, and remote branch management for effective team collaboration.

← Nginx Tutorial - Getting StartDocker Compose Build Command β†’