DEV Community

loading...
Cover image for Push git cloned repository to your own on GitHub

Push git cloned repository to your own on GitHub

dance2die profile image Sung M. Kim Originally published at slightedgecoder.com on ・2 min read

** UPDATE: April 21, 2019 **

Both Eugene Karataev & Noah Pederson provided a better way than what's in this post.

Check'em out below.

It's not necessary to remove old origin and create a new one. You can just change the existing origin url:
git remote set-url origin NEW_URL


Instead of creating a new repo, why not just create a fork then set the remote the same way? The git history should be the same, and GitHub will still track it as a forked repository


You git cloned a repository from GitHub without forking it.

The problem is that you made a bunch of changes and want to publish it to a new GitHub repository.

What are the steps required to accomplish it?

TL;DR

Remove original remote and add your own

Scenario

Suppose that you are taking an advantage of all javascript boilerplates floating around on GitHub since setting up Webpack and environment required manually for simple code is a bit too much.

Problem

But when you try to commit the code back to GitHub, you get an error message that you don’t have a permission since the cloned repo belongs to another user.

How to commit to your own GitHub repository

First, remove the remote repository associated using git remote rm origin.

Then create your own repository on GitHub.

Crete a new repository

After creating the repository, copy the repo URL.

copy the repo

Now, add the URL to your repo.

Now you can push/publish it to your own repository!

Wolla! It’s committed to your GitHub repository.

github page

Alternative

You can simply download a zip version of the repository, git init, then add the remote yourself if you are uncomfortable with git clone.

Resources

Help me improve this~

Git command is very flexible that there might be other ways to do it much easier. Please let me know if there is a way to do it without going through all these troubles πŸ™‚.

The post Push git cloned repository to your own on GitHub appeared first on Slight Edge Coder.

Discussion (11)

pic
Editor guide
Collapse
karataev profile image
Eugene Karataev

It's not necessary to remove old origin and create a new one. You can just change the existing origin url:
git remote set-url origin NEW_URL

Collapse
dance2die profile image
Sung M. Kim Author

πŸ‘†
Wow 😲, Eugene. Thanks for the set-url option.

To borrow from SQL, my posts is using "DELETE" then "INSERT"

while your command does an "UPDATE".

Much simpler.

Collapse
zeshhaan profile image
Mohammed Zeeshan

So does this preserve editing history?

Collapse
chiefnoah profile image
Noah Pederson

Instead of creating a new repo, why not just create a fork then set the remote the same way? The git history should be the same, and GitHub will still track it as a forked repository

Collapse
dance2die profile image
Sung M. Kim Author

That is a better option than what the post showed πŸ‘

I've only learned of it recently when someone forked my repo and renamed it to create a useful library out of it.

edewit / react-use-sessionstorage

βš“ React hook for using local storage

react-use-sessionstorage

Fork of github.com/dance2die/react-use-loc... but then uses session storage instead of local storage.

How to use it

import React from 'react'
import ReactDOM from 'react-dom'
import useLocalStorage from 'react-use-sessionstorage'
import './styles.css'
function App() {
  const [item, setItem] = useSessionStorage('name', 'Initial Value');

  return (
    <div className="App">
      <h1>Set Name to store in Local Storage</h1>
      <div>
        <label>
          Name:{' '}
          <input
            type="text"
            placeholder="Enter your name"
            value={item}
            onChange={e => setItem(e.target.value)}
          />
        </label>
      </div>
    </div>
  );
}

const rootElement =
…
Collapse
donblanco profile image
Glenn Dixon

I tried the 'set-url' and it did not work. Following the remove instructions did, thanks!

Collapse
dance2die profile image
Sung M. Kim Author

Weird that set-url didn't work.

Any errors thrown?

GitHub documentation still shows it as a valid option.

help.github.com/en/github/using-gi...

Collapse
saiafonua profile image
Saia Fonua

Thank you good sir!

Collapse
dance2die profile image
Sung M. Kim Author

You're welcome~

Collapse
fahadzakir7 profile image
Fahad Zakir

Awesome, got all three ways of doing this, best part was posting the suggested ways on top as well.

Thanks from a newb.

Collapse
ofu997 profile image
Oliver Fu

Thanks. I was wondering about boilerplates and whether I needed to publish my own npm package. I hope this works if the original repository is also your own.