Is it possible to add a project that is only stored on my local machine to a branch of an existing project on Github.
For example add:
local-project
to the Github repo:
https://github.com/myusername/my-project/local-branch.git
Can this be done or should the local repo first be pushed to it's own Github repo?
Additional info: Here is some extra info as per the comments I have received so far. So basically I have a Github repo (my-project) that contains a Next.js project that is currently in production. I would like to update this project to a completely different language (REACT NATIVE), that is currently still in development. The React Native version I have been working on is only locally on my computer, as I cloned a repo and haven't pushed it to Github yet. My ultimate goal is to have the React Native version as a branch (local-branch) in the (my-project) Github repo. Then when the local-branch is ready for production I can simply merge it to main.
CodePudding user response:
First of all: you can push a branch, not repository.
Now:
git remote add remote-repo <remote-repo-url>
git push remote-repo local-branch:<remote-new-branch-name>
CodePudding user response:
First to clarify some terminology, you can't "push a local repository". Instead, you can push a branch from your local repo to a remote repo. First you need to create a remote:
git remote add <name> <url>
For example
git remote add my-remote https://github.com/myusername/my-project/local-branch.git
By default, git will create a remote named origin
when you git clone
another repo.
Once you have a remote, you can push your branch:
git push my-remote my-branch
While you can do this with any branch and any repo, it usually only makes sense if the two repositories have a common history, such as when you clone a github repo locally or if you create a new repo locally and want to push a branch to an new, empty repo on github.