简体   繁体   中英

How to push my branch to master repository?

I am developing code in my (private) repository on branch 'my_branch'.

After some development I am happy with what I have done and I would like to save 'my_branch' to master repository (so it will not get lost in case my disk has a fault).

But I don't want to merge my changes to master branch yet.

I used command:

git push

and then:

got clone

and cloned master repository to a different directory. But I noticed that on that directory when I change to my_branch the files do not contain my changes.

Please help!

(It seems to me that everyone normally works in similar way: from time to time backing up your branch whilst not yet merging it to master?)

I used to work in ClearCase and what is good about it is: as soon as you check-in your file in your private branch, it can never get deleted, but from the other hand it is not on main branch and you can continue developing your code without disturbing other developers.

You can push your branch to an upstream repo (which isn't called "master", but "origin" by default: git push origin myBranch ), but when you clone, you clone by default the master branch, not myBranch .
And your branch isn't tracked by default.
Ie, you don't have a local branch myBranch on your clone, which track origin/myBranch (the branch fetch from the remote repo).

On your clone, you need to create a local branch for all the fetched remote branches.
See " Track all remote git branches as local branches ".


As I mention in " Sell me Distributed revision control ", branching is orthogonal to publishing (push/pull):

Each time I want to "check-in" changes on my branch - is it enough to call "git push origin my_branch" or "git push my_branch"

Any commit is a local one, as opposed to ClearCase (which commits on the LATEST of a centralized branch in a config spec).
See " What are the basic clearcase concepts every developer should know? " for the differences between ClearCase and Git.

So a simple commits remains on your local repo, invisible to all other developers.
If you push your branch to an upstream repo (see " Definition of “downstream” and “upstream” "), that branch will be cloned by other developers, but they won't see its content unless they checkout that branch in their own local repo.
By default, they would see the master branch.

No "special clone mode" needed: a clone would clone the all repository content, with all its history and branches.

Run

git push -u origin my_branch

Then in the future you can just run "git push".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM