<p dir="auto">Sometimes, when we work on a Tutorial, we want to wipe out our Project repository on GitHub and restart. Doing it from command line is easy and fast.
<p dir="auto">Let's say your username on GitHub is "<code>username" and you want to reset the project "<code>my-project". Open a console and do the following:
<h1>Delete your current project
<pre><code>$ ls -a
. .. my-project
$ rm -rf my-project
<p dir="auto">⚠ Performing <code>rm -rf from within your project directory will not work as it does not remove the hidden files and directories.
<h1>Reinitialize an empty Git Repository
<pre><code>$ mkdir my-project
$ cd my-project
my-project$ git init
Initialized empty Git repository in /home/username/projects/my-project/.git/
my-project$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
<h1>Link to GitHub
<pre><code>my-project$ git remote add origin git@github.com:username/my-project.git
my-project$ git remote -v
origin git@github.com:username/my-project.git (fetch)
origin git@github.com:username/my-project.git (push)
<h1>Force PUSH the new Repository
<pre><code>my-project$ touch README.md # 🅰
my-project$ git add .
my-project$ git commit -m "Initial commit"
[master (root-commit) b17b424] Initial commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 README.md
my-project$ git push -uf origin master # 🅱
Counting objects: 3, done.
Writing objects: 100% (3/3), 213 bytes | 213.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To github.com:username/my-project.git
+ ed755d5...b17b424 master -> master (forced update)
Branch master set up to track remote branch master from origin.
<p dir="auto">A few remarks:
<p dir="auto">🅰 You have to commit at least one file before you can push your repository to Git.
<p dir="auto">🅱 The flags we use when pushing are to force the reset of our repository on GitHub (<code>-f) and to set the remote <code>origin as default (<code>-u). After you run this comment, you will be able to push using just <code>git push.
<h1>Bash script
<p dir="auto">If you reset repositories a lot, you may want to create a bash script for this:
<p dir="auto"><br />
<div class="pull-right"><sup>`reset_git.sh
```bash
#!/bin/bash
echo "GitHub Repository Reset"
echo "GitHub username?"
read username
echo "GitHub repository?"
read repository
mkdir $repository
cd $repository
git init
git remote add origin git@github.com:$username/$repository.git
touch README.md
git add .
git commit -m "Initial commit"
git push -uf origin master
echo "Repository $repository for User $username has been reset!"
```
<p dir="auto">We deliberately didn't include the deletion (<code>rm -rf $repository) inside the bash script considering this to be too dangerous.
<p dir="auto">So, after you change the execution permission on the script (<code>chmod +x reset_git.sh) you may run it as:
<pre><code>$ rm -rf my-project
$ ./reset_git.sh
GitHub Repository Reset
GitHub username?
username
GitHub repository?
my-project
Initialized empty Git repository in /home/username/my-project/.git/
[master (root-commit) 8d7d600] Initial commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 README.md
Counting objects: 3, done.
Writing objects: 100% (3/3), 214 bytes | 214.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To github.com:username/my-project.git
+ 479bc7e...8d7d600 master -> master (forced update)
Branch master set up to track remote branch master from origin.
Repository my-project for User username has been reset!
Congratulations @thierrydd! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
<p dir="auto"><a href="http://steemitboard.com/@thierrydd" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link"><img src="https://images.hive.blog/768x0/https://steemitimages.com/70x80/http://steemitboard.com/notifications/post4day.png" srcset="https://images.hive.blog/768x0/https://steemitimages.com/70x80/http://steemitboard.com/notifications/post4day.png 1x, https://images.hive.blog/1536x0/https://steemitimages.com/70x80/http://steemitboard.com/notifications/post4day.png 2x" /> You published 4 posts in one day <p dir="auto">Click on any badge to view your own Board of Honor on SteemitBoard.<br /> For more information about SteemitBoard, click <a href="https://steemit.com/@steemitboard" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">here <p dir="auto">If you no longer want to receive notifications, reply to this comment with the word <code>STOP <blockquote> <p dir="auto">Upvote this notification to help all Steemit users. Learn why <a href="https://steemit.com/steemitboard/@steemitboard/http-i-cubeupload-com-7ciqeo-png" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">here!