Jaylen
Jaylen

Reputation: 40279

How to maintain two versions of a project on GitHub?

I have a project on GitHub. I started a new branch on my machine when all my new code goes. I want to be able to keep support the currently stable version. Also, I want all new features to go to the new branch.

Locally, I have two branches master-dev and v2.0. However, I want to push both branches to GitHub so my code in backed up.

My master-dev branch is already on GitHub. I just want to push the new branch v2.0.

While in my v2.0 branch, I did the following

  1. git add .
  2. git commit -m="Some Message"
  3. git push

However, that gave me the following error

fatal: The current branch v2.0 has no upstream branch. To push the current branch and set the remote as upstream, use

git push --set-upstream origin v2.0

I don't know what will that command do, I just want to make sure I don't mess up my existing project.

How to maintain both of my branches GitHub?

Upvotes: 1

Views: 1225

Answers (1)

Marina Liu
Marina Liu

Reputation: 38096

For the branches which have already exist in remote, you can use git push or git push origin branchname.

But when you push the new local branch in local which is not exist in remote, you need to set upstream (tracking branch), you need to set which branch you want push to remote. You can use any of the below commands:

git push origin v2.0
git push -u origin v2.0
git push --set-upstream origin v2.0

For git push origin v2.0, it will create a remote branch v2.0 and push changes in local v2.0 into it.

For git push -u origin v2.0 and git push --set-upstream origin v2.0, they have same function. Both of them create the branch v2.0 in remote and push changes in local v2.0 into it. The difference between the first command is this two commands set the tracking reference between local v2.0 branch and remote v2.0, you can use git branch –vv to find the relationship.

Upvotes: 3

Related Questions