Push to an existing GitHub repo as different branch from a New Project(local non-git repo)

NB: If the code you have is cloned from a Git repo and you want to push the code to new branch the scroll to second section

Push to an existing GitHub repo as different branch from a New Project(local non-git repo)

When you have finished working with a project which is not a git repo(local repo) and you need to push the code to an existing GitHub repo as need branch you can follow these steps. Hope you know about Git and GitHub, so I'm not spending time on explaining it.

So Lets Get Started!

  1. Hope you already have a GitHub repository which will have a main branch(by default). Once you finish testing your code, in the terminal use the below commands one by one:
git initgit add .git commit -m “Initial Commit”

2. Now we have to mention the branch. As of now I will name my branch as test. You can name your branch as you wish

git branch -m test

3. Once you add the branch, mention the origin by adding the repository link from GitHub.

GitHub Repository Link
git remote add origin https://github.com/AlexyPulivelil/testbot.git

4. Finally push the code to right branch.

git push -u origin test

Now you have successfully pushed your new code to a new branch of existing repo.

Push To New Branch

  1. Use the below command to create new branch
git checkout -b test

2. Follow the basic commands to push the code.

git init 
git add .
git commit -m “Type your msg”
git push -u origin test

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store