Git, local push '' from the function branch to the wizard, without checking

I would like to team up with FeatureBranch to deal with it without doing a "checkout master". I tried (being in FeatureBranch)

git push . master 

but I got (to a degree of surprise):

 Everything up-to-date 

Despite the fact that there are commits in FeatureBranch that are not yet present in the main.

The reasons I want to be able to do a one-step local push ':

  • I want to make changes to my employees who remain on the main branch.
  • no extra step: checkout master ''
  • thereby being able to stay in FeatureBranch
  • and avoid quickly changing many files that confuse / warn many tools that are related to files / files in the repo

I know that I can do this in several steps in different ways. But I wonder if there is a one-step solution to this (I think it should be).

I think / understand that if conflicts arise, I still have to switch to mastery. But in most cases, I have no conflicts and, therefore, you will get a one-step solution.

My git version:

 git --version git version 1.6.5.1.1367.gcd48 

(Windows)

TIA
karolrvn

+4
source share
5 answers

The question " Merging branches without validation " provides excellent answers explaining why validation is required.
Saving a separate repo (with checking the target branch) is another way.

But the main thing remains: push / pull - about remote repositories.
Place an order for a local repo.

Git data transport commands

If you have this scheme, you understand that you do not click on master .

0
source

Regarding your question about why the push command acts as if it ...

Push is used to distribute commits from one repository to another, and not from branches within the repository. In your case, you are switching from one repository to the same repository, so the answer is "Everything is up to date", as it should be. The fact that you name two different branches does not matter in this case.

+3
source

You cannot commit a branch other than the current; or, to put it another way, the new node created by git commit is always a child of the current HEAD.

I sometimes used separate rehearsals of the "production" to avoid the overhead of switching branches in my live development environment:

 # Currently working on branch 'foo' in $SOME_DIR/main-repo # main-repo is a local clone of shared-repo # Create the staging repo alongside the existing main-repo cd $SOME_DIR git clone shared-repo staging-repo cd staging-repo git remote add local ../main-repo # Switch back to main-repo and continue working cd main-repo # (Make changes and commit to branch foo ...) # Switch to the staging repo cd $SOME_DIR/staging-repo # Make sure we are up to date with shared repo (*) git pull # Merge changes from main-repo git fetch local git merge local/foo # Push changes up to the shared repo git push 

The potential problem with this approach is that it does not allow you to check the result of the merge in the changes made on the foo branch with what was done in shared-repo / master (*) . Depending on the nature of the changes, this may be okay, but in most cases you need to at least perform a quick health check (for example, check that the code is still compiling, possibly run smoke tests) before going into general repository.

For this you will need:

  • build staging-repo - but in this case the merge can be done directly in main-repo
  • have an intermediate repo in a separate build environment from main-repo, i.e. $SOME_OTHER_DIR/staging-repo . This will allow you to create and / or test the creation of a repo without polluting the environment of the main repo.
+1
source

It seems that what you really want to do is a merger, not a push? Unfortunately, I do not think that this is possible without being on the branch that is the target of the merge, so the sequence of commands will be as follows:

 git checkout master git merge FeatureBranch git checkout FeatureBranch 

This whole operation will take less than a second, so I'm not sure why you strongly object to switching to the main branch for this ...

0
source

I had the same problem, and based on your idea, I found the solution quite simple:

 git push . HEAD:master 

this works as long as the wizard can be quickly redirected to the current head, i.e. you launched your current branch on the main server and have not received any new commits to the master since.

0
source

Source: https://habr.com/ru/post/1301833/


All Articles