Git Topics (9)Tap to view
    Git·Version Control·Topic 7 of 9

    Git Remotes & Sync

    Connect remote repositories, fetch updates, sync, secure push using force-with-lease.

    1. Remote Repositories and Synchronization

    1. git remote -v

      What it doesDisplays the names and addresses of the remotes registered for the repository (fetch and push)

      When to use itto check the associated remote servers

      Examplegit remote -v

    2. git remote add origin <url>

      What it doesLink the local repository to a new remote repository named origin

      When to use itWhen a new local repository is uploaded to GitHub for the first time

      Examplegit remote add origin git@github.com:user/repo.git

    3. git fetch origin

      What it doesFetch all updates and branches from remote without merging them into your local branch

      When to use itTo see what is new on the server safely and without surprises

      Examplegit fetch origin

    4. git pull

      What it doesFetches updates and automatically merges them into the current branch

      When to use itto update the regular local branch

      Examplegit pull

    5. git pull --ff-only

      What it doesFetch and update the branch only if it can be Fast-Forward updated without creating a merge commit

      When to use itTo maintain the cleanliness and integrity of the history of the local branch

      Examplegit pull --ff-only

    6. git pull --rebase origin main

      What it doesFetches and reapplies local changes over the latest update of the remote branch

      When to use itbefore payment to avoid unnecessary merge commit

      Examplegit pull --rebase origin main

    7. git push

      What it doesUploads local commits to remote branch

      When to use itto publish edits after commits

      Examplegit push

    8. git push -u origin <branch>

      What it doesAutomatically raises the branch and sets upstream tracking

      When to use itWhen a new branch is first pushed to the remote

      Examplegit push -u origin feature/login

    9. git push --force-with-lease

      What it doesA safer version of force push that checks for changes you did not see before replacing remote history

      When to use itAfter rebase or commit --amend on your own branch

      Examplegit push --force-with-lease origin feature/login

    Offline · Reading cached copy