Skip to content

Instantly share code, notes, and snippets.

@cemerson
Created December 5, 2024 18:56
Show Gist options
  • Save cemerson/a3f53f8619c75bcef7246cbc17fc799f to your computer and use it in GitHub Desktop.
Save cemerson/a3f53f8619c75bcef7246cbc17fc799f to your computer and use it in GitHub Desktop.
Git - fix local dev branch out of sync with remote

resolving issue where local development branch is out of sync has odd/new merge issues not on remote/azure/github ...

To reset your local development branch to match the remote branch from Azure DevOps (or any remote repository), you can use the following steps. This will overwrite your local branch completely with the latest version from the remote.

Steps to Reset development to Match Remote:

  1. Switch to the development branch:

    git checkout development
  2. Fetch the latest updates from the remote repository: This step ensures you have the latest commits and metadata from the remote.

    git fetch origin
  3. Reset your local development branch to match the remote branch: Use reset --hard to overwrite your local branch with the remote branch.

    git reset --hard origin/development
    • origin/development refers to the remote branch named development.
  4. Ensure your working directory matches the branch: To clean up untracked files that might cause conflicts, run:

    git clean -fd
    • The -f flag forces the removal of untracked files.
    • The -d flag removes untracked directories.
  5. Verify the branch state: To confirm your branch is aligned with the remote, use:

    git status

Key Notes:

  • Warning: The reset --hard command discards any local changes that have not been committed. Ensure you back up any important changes before running this.
  • If your local branch is behind but you have local commits you want to preserve, consider using rebase or merge instead of reset.
  • If you renamed the remote repository (e.g., something other than origin), replace origin with the name of your remote.

After these steps, your local development branch should exactly match the remote development branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment