Array
University of Oregon

Git: Rollback & Start Over

git-logoIf Git is not cooperating with you, sometimes the best and easiest solution is to just start over.

The following example is written for a project directory named p1, but the same steps apply to any project directory.

 

  1. Double-check the current directory is correct.
    pwd
    ~/Documents/repos/281/Projects/p1/


  2. Delete the current repo: remove the .git directory.Git stores all its information in a directory named .git. By removing this directory, you “de-repo-fy” your directory.Caution: If you omit the reference to .git in the following command, you may accidentally delete all files in the current directory.rm    -Rf    .git
    git   init


  3. Create a new repo.
    git init


  4. Add a remote.A remote is a bookmark to your remote repo on Github.a) In Chrome, open your project repo on Github
.b) Copy the Clone URL:

    c) Add the remote. Be sure to use your Github HTTPS URL in the following:

    git   remote   add   origin    https://github.com/UO-CIT/susanq-382.git


  5. Add all your files to your repo:git add -a
    git commit -m “First commit”


  6. Push your repo to Github.
    “-f” is “force push” to override all content on the master branch on the remote repo.git   push  -f  origin  master


  7. Open your Github remote repo in Chrome, and examine.
  8. If you have other branches on your remote repo, delete each of them now:git branch -d branch-name

You are now ready to continue working on your project.

Another Way to Roll-Back: Revert

Read how to use the  “git checkout” command to revert to an earlier commit.

Skip to toolbar