DJ-DOO
DJ-DOO

Reputation: 4781

Git - How to add local repository to new Branch

I'm working on a project where we have reached a milestone. My git repository is up to date and everything is working correctly. Our client has now updated their api's and we're unsure how it will affect our code.

What I want to do is create a branch (already done) and upload the full repository to the branch. So I will have the project duplicated, one in the master and one in the new branch. I will then work and commit to the new branch leaving the master untouched. So going forward then for each release I can do the same, so we can fall back to the previous branch if there's any problem.

Can someone tell me how to do this please. I'm using Git and I'm working through a mac terminal.

I've gone through relevant questions on SO but I don't see the info I require, or perhaps I've missed it.

Upvotes: 0

Views: 46

Answers (2)

Gauthier
Gauthier

Reputation: 41955

You don't upload a repository to a branch.

You have your code in a repository, and the repository has branches. No duplication, but you can get (checkout) master or the branch to set your working files to the version you want: master for untouched changes, branch for your recent changes.

Always good to do when you have reached a milestone is to tag the commit:

$ git tag v1.0

Then from there you can start a branch to work on integrating the new API

$ git checkout -b client_api_update

Work and commit in your branch. It does not affect the content in master, which you can checkout when you want to get your working files as they were in your milestone version (or checkout the tag).

When the integration of the new API is done, it's time to merge your branch to master in order to release support of the new API:

$ git checkout master
$ git merge client_api_update --no-ff

--no-ff is optional, but I think it makes for a more elegant history.

You are at a new milestone, so tag:

$ git tag v1.1

Here is how your history would look like:

    /- v1.0            /- v1.1 
A---B------------------G - master
    \---C---D---E---F-/ - client_api_update

Upvotes: 1

svlasov
svlasov

Reputation: 10455

Let's say the branch you created in the main repo is <main_repo_new_branch>. Then the steps would be:

cd <local_repo_dir>
git remote add mainrepo <main_repo_dir>
git push mainrepo <local_repo_branch>:<main_repo_new_branch>
cd <main_repo_dir>
git checkout <main_repo_new_branch>

Upvotes: 0

Related Questions