Grant
Grant

Reputation: 21

Push a new version using git without losing the old one

I'm learning to use git and right now I have a project, I'm using bitbucket to keep my code and I know how to update it, the thing is that right now I made some mayor changes to my code and I want to upload it but without losing or updating the code already on bitbucket, how can I do that? I can't find the command.

Is a branch the same as a version? For example if I create a branch:

git checkout -b <new-branch>

this branch will be like say project v1.2?

Upvotes: 2

Views: 1885

Answers (3)

Himanshu Gupta
Himanshu Gupta

Reputation: 440

There are some standard you have to understand which developers are using. Create a branch from master to develop and develop to yourBranch.

Mater -> develop -> yourBranch

You Probably do changes in yourBranch, merge into develop, then develop to create release branch and merge in master, and create a new tag and push into production. This new tag will have all your change and old code also.

V1.2(Tag) <- Mater(branch) <- releaseV1.2(branch) <- develop(branch) <- yourBranch(branch)

Tag Commands

# To get latest tag using command
git describe

# To create new tag
git tag v1.1

# To uploads all your tags in origin
git push --tags

Branch Commands

# To create a new branch
git branch branchName

# To checkout in branch 
git checkout branchName

# Create a new branch and checkout in that branch
git checkout -b branchName

# To pull branch in origin
git pull origin branchName

# To add all files in which you have done changes
git add .

# To add single file in which you have done changes
git add pathToFile/fileName

# To commit your changes
git commit -m "Your message, what changes you have done"

# To push your changes in origin remote 
git push origin yourBranch

Upvotes: 1

Viacheslav Shalamov
Viacheslav Shalamov

Reputation: 4427

There is no need to use branch for that.

Every time you do a commit, the corresponding version is stored in your repository. You can access it later via git checkout or bitbucket gui.

All you need to do is to add (git add) your files to repository, and then use git commit -m "added support of this.." to commit the current state of your code (all files you added).

After you make some changed to files, you do git commit -m "fixed issue about ... ", and this version will be also stored in history.

Note that commits are about (usually) small incremental changes in your code. For release management and versions (v.1.0, v.2.2 etc) you can use tags, as @Schwern suggested in comments below.

Upvotes: 5

Schwern
Schwern

Reputation: 165546

If I understand what you're asking for, you want to be able to update your project, but still allow people to download this version. You want people to be able to download v1.1 while working on v1.2.

In version control this is usually done with a tag. A tag simply puts a label on a commit. It's kind of like a branch, but it never moves. Then people can checkout that tag. For example...

# This tags the current commit as v1.1
git tag v1.1

# This uploads your tags.
git push --tags

# Then anyone can checkout v1.1
git checkout v1.1

Using tags for releases allows anyone to easily checkout a release, and you can continue to commit small changes with good commit messages.

Here's Bitbucket's own documentation about tagging.

Other systems like Github go a step further and turn your tags into "releases" which are downloadable from their web site. Bitbucket does not appear to support this feature, but it seems it's in the works.


As for branching, if v1.1 is done then there's no need to branch for a new release. Continue working on master and making new tags for new releases.

Where version branches are appropriate is for very large projects which have to maintain multiple major versions simultaneously. For example, a programming language might need to maintain v2 while working on v3 at the same time. So they might have a v2 branch and a v3 branch. Each would still have their own tags (v2.2.4, v3.0.3, etc...).

Upvotes: 0

Related Questions