0

I am using Git version 2.27.0.

I made a mistake.

I was supposed to run this command to switch to another branch:

git checkout CTNG-52-flight-result-form-changes

But I ran this instead:

git branch CTNG-52-flight-result-form-changes

Problem

This has now created CTNG-52-flight-result-form-changes on my local repo. CTNG-52-flight-result-form-changes already existed on the remote repo, and now I don't want to make any changes to the remote repo, but I just want to checkout the remote repo branch (CTNG-52-flight-result-form-changes).

Question

How do I revert the git branch CTNG-52-flight-result-form-changes command without affecting anything on the remote repo?

More Info

Here is a log of my commands I ran:

Richards-MacBook-Pro:nexct-ng-ui richardmarais$ git branch
* develop
  login-changes
  master

Richards-MacBook-Pro:nexct-ng-ui richardmarais$ git fetch
remote: Counting objects: 1598, done.
remote: Compressing objects: 100% (831/831), done.
remote: Total 1598 (delta 1159), reused 1075 (delta 752)
Receiving objects: 100% (1598/1598), 425.01 KiB | 773.00 KiB/s, done.
Resolving deltas: 100% (1159/1159), completed with 39 local objects.
From https://bitbucket.org/travellinckcorpdevelopers/nexct-ng-ui
 * [new branch]      53-flight-results                  -> origin/53-flight-results
 * [new branch]      CS-BookANewTrip                    -> origin/CS-BookANewTrip
 * [new branch]      CS-Dashboard-Develop               -> origin/CS-Dashboard-Develop
 * [new branch]      CS-request-newdashtrip             -> origin/CS-request-newdashtrip
 * [new branch]      CS-update-my-trips                 -> origin/CS-update-my-trips
 * [new branch]      CTNG-24-my-trips-page              -> origin/CTNG-24-my-trips-page
 * [new branch]      CTNG-25-book-new-trip              -> origin/CTNG-25-book-new-trip
 * [new branch]      CTNG-25-request-a-trip             -> origin/CTNG-25-request-a-trip
 * [new branch]      CTNG-52-flight-result-form-changes -> origin/CTNG-52-flight-result-form-changes

Richards-MacBook-Pro:nexct-ng-ui richardmarais$ git branch
* develop
  login-changes
  master

Richards-MacBook-Pro:nexct-ng-ui richardmarais$ git branch CTNG-52-flight-result-form-changes

Richards-MacBook-Pro:nexct-ng-ui richardmarais$ git branch
  CTNG-52-flight-result-form-changes
* develop
  login-changes
  master

Richards-MacBook-Pro:nexct-ng-ui richardmarais$ git checkout CTNG-52-flight-result-form-changes
M       nexct-ng-ui/package-lock.json
Switched to branch 'CTNG-52-flight-result-form-changes'

Richards-MacBook-Pro:nexct-ng-ui richardmarais$ git pull
warning: Pulling without specifying how to reconcile divergent branches is
discouraged. You can squelch this message by running one of the following
commands sometime before your next pull:

  git config pull.rebase false  # merge (the default strategy)
  git config pull.rebase true   # rebase
  git config pull.ff only       # fast-forward only

You can replace "git config" with "git config --global" to set a default

Richards-MacBook-Pro:nexct-ng-ui richardmarais$ git branch
* CTNG-52-flight-result-form-changes
  develop
  login-changes
  master

Richards-MacBook-Pro:nexct-ng-ui richardmarais$ git checkout develop
M       nexct-ng-ui/package-lock.json
Switched to branch 'develop'
Your branch is up to date with 'origin/develop'.

Richards-MacBook-Pro:nexct-ng-ui richardmarais$ git branch
  CTNG-52-flight-result-form-changes
* develop
  login-changes
  master
Biffen
  • 6,249
  • 6
  • 28
  • 36
Richard
  • 8,193
  • 28
  • 107
  • 228
  • Does this answer your question? [Deleting a local branch with Git](https://stackoverflow.com/questions/41492254/deleting-a-local-branch-with-git) – Joe Mar 26 '21 at 10:02

1 Answers1

1

With your git branch CTNG-52-flight-result-form-changes you have created a branch with name CTNG-52-flight-result-form-changes that doesn't track any remote branches, so you can delete it freely with following command:

git branch -d  CTNG-52-flight-result-form-changes

In order to checkout CTNG-52-flight-result-form-changes from the remote and set your local copy to track the remote, use this command:

git checkout -b  CTNG-52-flight-result-form-changes origin/CTNG-52-flight-result-form-changes
Monsieur Merso
  • 1,459
  • 1
  • 15
  • 18