1

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.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
Andrey Rubliov
  • 1,359
  • 2
  • 17
  • 24

2 Answers2

0

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Read also http://stackoverflow.com/questions/2563836/sell-me-distributed-revision-control/2563917#2563917: don't mix upstream repo (like 'origin') and branches (like 'master'). ClearCase is mostly a *centralized* VCS, not a DVCS: see http://stackoverflow.com/questions/645008/what-are-the-basic-clearcase-concepts-every-developer-should-know/645771#645771 for the difference between the two. – VonC Nov 06 '12 at 10:31
  • Thank you! I am just trying to understand the workflow. 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" ? But if someone will want to clone my changes he will beed to use s special clone mode? – Andrey Rubliov Nov 06 '12 at 11:22
  • @AndreyRubliov I have edited the answer to address your points. If you need to update the master branch, then you would need to rebase first your branch on top of master, and then push master. See http://stackoverflow.com/questions/804115/git-rebase-vs-git-merge/804178#804178 – VonC Nov 06 '12 at 11:38
0

Run

git push -u origin my_branch

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

user1338062
  • 11,939
  • 3
  • 73
  • 67