Skip to content
X

Cloning and Customizing a Repository

This page explains how to create your own repository based on a template or an existing project. By understanding the relationship between origin (your repository) and upstream (the original repository), you can safely customize the project and bring in updates later.

  • Git is installed
  • You have created a GitHub account
  • You have access to a terminal in an environment such as VS Code

First, create a new repository for yourself on GitHub.

  1. Sign in to GitHub
  2. Click + in the upper-right corner, then click New repository
  3. Enter a name in Repository name (example: your-repo-name)
  4. Choose Private (or Public if you want it visible)
  5. Click Create repository

The resulting URL looks like this:

https://github.com/you/new_repo.git

Clone the Template and Disconnect the Original Remote

Section titled “Clone the Template and Disconnect the Original Remote”

Clone the template repository and disconnect the original origin.

# Clone the template repository
git clone https://github.com/someone/original_repo.git
cd original_repo

# Check current remotes
git remote -v

# Remove the original origin connection
git remote remove origin

# Confirm nothing is listed
git remote -v

💡 git remote remove origin only removes the remote connection. It does not delete your local files.

Connect Your Own Repository and Make the First Commit

Section titled “Connect Your Own Repository and Make the First Commit”

After disconnecting the original remote, register your own repository as the new origin and push the first commit.

# Stage and make the initial commit
git add .
git commit -m "Initial commit"

# Add your own repository as origin
git remote add origin https://github.com/you/new_repo.git

# Push main and set tracking
git push -u origin main

Now your local repository is connected to your own remote. From now on, git push alone is enough.

⚠️ If git push -u origin main says that the main branch does not exist, the template may still be using master. Run git branch -M main first, then push again.

If the original template changes, set up upstream so you can pull those changes in later.

# Add upstream
git remote add upstream https://github.com/someone/original_repo.git
git remote -v

# Fetch the latest information and merge it
git fetch upstream
git checkout main
git merge upstream/main

⚠️ If a conflict occurs during the merge, fix the file manually. After that, run git add <file> and git commit to finish.

After a successful merge, push the changes to your own remote:

git push origin main

Your final remote configuration should look like this:

origin    https://github.com/you/new_repo.git (fetch)
origin    https://github.com/you/new_repo.git (push)
upstream  https://github.com/someone/original_repo.git (fetch)
upstream  https://github.com/someone/original_repo.git (push)
Remote nameRepositoryPurpose
originYour repositoryDaily push / pull
upstreamThe original templatePulling in updates

You added the wrong URL to a remote

git remote set-url origin https://github.com/you/correct_repo.git

Branch name mismatch (main vs master)

# Standardize the branch name to main
git branch -M main
git push -u origin main

Push was rejected because the remote is newer

git pull --rebase upstream main

Authentication errors appear

Switching from HTTPS to SSH may solve the problem.

git remote set-url origin git@github.com:you/new_repo.git

💡 Create a new branch before you start working so you have a safety net if something goes wrong. Get in the habit of creating a backup branch with git checkout -b feature/backup.

StepCommand
Clone the templategit clone <URL>
Remove the original remotegit remote remove origin
Connect your own repositorygit remote add origin <URL>
Make the initial commit and pushgit push -u origin main
Register upstreamgit remote add upstream <URL>
Pull in updatesgit fetch upstream -> git merge upstream/main

Q. Do I need git init?

No. A cloned repository already has a .git folder, so git init is not needed. You only need git init when starting a completely new project from scratch.

Q. Do I have to set up upstream?

Not if you do not plan to pull in template updates. However, it is convenient to set it up from the beginning, so I recommend registering it during setup.

Q. What does -u in git push -u origin main mean?

-u is short for --set-upstream, which sets the tracking relationship between the local branch and the remote branch. Once it is set, you can use git push alone next time.