DEV Community

Cover image for Push project from existing repo to new repo
Olawale Adepoju for AWS Community Builders

Posted on • Originally published at dev.classmethod.jp

Push project from existing repo to new repo

Summary

Image description

I needed to build a new project from an existing project which I already had in a remote repository at some branch.I could do it manually by copying and pasting it into a new repo, but I prefer using a better way with the help of git.

Adding new remote repo into existing git project

cd to the project directory

$ cd existing-project-name
Enter fullscreen mode Exit fullscreen mode

List current remotes:

$ git remote -v
origin https://github.com/existing-repo.git(fetch) 
origin https://github.com/existing-repo.git(push)
Enter fullscreen mode Exit fullscreen mode

Add new origin (origin2):
(Because Git uses origin by default, let's create a new origin as origin2).

$ git remote add origin2 https://github.com/new-repo.git
Enter fullscreen mode Exit fullscreen mode

Let's see added origin:

$ git remote -v
origin https://github.com/existing-repo.git(fetch) 
origin https://github.com/existing-repo.git(push) 
origin2 https://github.com/new-repo.git (fetch)
origin2 https://github.com/new-repo.git (push)
Enter fullscreen mode Exit fullscreen mode

Pushing specific branch of the new repository:

On the existing repo, my project is on the master branch, while I want to push it to the main branch on my new repo.

The following command pushes a specific branch (master) from the current repo to the main branch of the new repo, with the remote set to origin2.

$ git push origin2 source_branch:destination_branch

If necessary, use --force to forcefully push into the new branch.

$ git push origin2 master(source-branch):main(destination-branch) --force
Enter fullscreen mode Exit fullscreen mode

I hope this helps when trying to push from the existing repository to the new repository.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Best Practices for Running  Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK cover image

Best Practices for Running Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK

This post discusses the process of migrating a growing WordPress eShop business to AWS using AWS CDK for an easily scalable, high availability architecture. The detailed structure encompasses several pillars: Compute, Storage, Database, Cache, CDN, DNS, Security, and Backup.

Read full post