When do I need to pull before I can push Git?

If A and B are running on the same git repository, and A is pushing changes to feature branches: A-feature

to the repo before B , B now needs to be pulled before it can push.

But where is the exact condition for this described? For example. does it apply to any changes in any branch redirected to the repo? Or is it only if A and B pushed on the same branch? So B can click on B-feature

even though A just clicked in A-feature

front of it?

+3


source to share


3 answers


So B can click on the B-function even though A just clicked on the A-function in front of it?

Yes. The warning you get is only when you push on a branch updated by someone else:

hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.

      



The only alternative git pull

would be git push --force

(which overwrites the history posted A

with B

's if it B

should have been clicked A-feature

, which is bad.).
See " git push --force

Behind the Scenes
".

If on B

only works B

, pushing B

doesn't need to pull the local branch B-feature

into the upstream repository: pushing is fast: you're adding new commits on top of the remote branch.

+4


source


The reason B will have to commit changes to A before he (or she) can commit his changes to the same branch is because otherwise B will be rewriting history (deleting A commits in favor of their own) and End (which not part of local branch B) will be lost.

This is only in case you push to the same branch, so yes, B can push to another branch without having to pull. In this case, the merging of commits A and B will occur later, when their branches are merged.



If you do want to push to the remote branch, even if it contains commits that are not in your local branch, you can tell git not to warn you and continue with push anyway using git push --force

(or git push -f

). However, be careful, as in most cases (especially when you work with other people), this is not recommended. Commits that are not on your local branch will be removed from the remote branch.

+3


source


Each branch in Git is a chronological sequence of commits.

If you want to push a commit that is not based on the last commit of that branch, you first need to do an intermediate commit (which may involve a manual merge).

This is only a problem when multiple users push on the same branch. With each user working separately on a private thread, they never have to pull to push. Unless, of course, they intentionally want to merge another's branch.

+2


source







All Articles