Gitcmd-2016.html: Old meanwhile invalid document from 2016

1. Branches and Contribution

1.1. push the own work

Presumed, on the own working environment there is a git archive started from a dedicated version:

A-B-C(master) .... this version, master branch

Now a contributer makes some changes by itself, tests it and would push it. But the contributer may have not the overview about the whole project.

In the own environment of the contributer the archive shows:

A-B-C-D(master).... D is the new version in the own branch, it is the master branch

If nobody else has committed, then the push changes the master branch on the central repository. This may not be expected or desired. Firstly the maintainer should check the version D.

If another commit exists then the master branch has the structure:

A-B-C-D-E(master) ... D and E are other commits!

On a simple

git push urlpath/to/central/.git

an error message occurs "cannot push…​". That is ok.

Usual a "merge" should be done. But this merge may not be allowed by the contributer, because he/she may not have the full overview. For the same reason the contributer should nothing change on his own repository in respect to the remote changes. It means, a "pull" of any new versions should not be done. The contributer should only push his/here own work.

A second approach: The contributer should anyway not change the master branch, because the work should be firstly reviewed.

The working goal is, to create a local branch. This can be done also after the own commit in the own archive as "master":

git checkout -b localName

The wording "checkout" is a little bit misleading. It may be correct from the view on the central repository, and anybody gets a version for his own. But from the point of view of the own repository, which is already pulled (or just fetched or checked out), this command should be better named as "makebranch" or better "rename" (of the own branch). But the names of the git commands cannot be discussed.

After this checkout the following is gotten:

A-B-C-D(localName).... D is the new version in the own branch, designated as localName branch

posibility todo use

git branch rename ok

renames the current branch to another name.

Now the push is possible, with an additional option:

git push --set-upstream urlpath/to/central/.git localName

As result in the central repository is shown:

A-B-C-D-E(master) ... D and E are other commits!

or also maybe:

A-B-C(master) ... D and E are other commits!

Now the localName is firstly not interesting for other people. Only the maintainer can view the change, make a merge, and inform the contributer to use the new master version for further development.