简体   繁体   中英

Can I push changes of one repository to another in Git?

I am working on a project currently and my employer has given me write access to the main repository of the project where he merged the repository in which I was working I think. A particular branch is specified to me.

Now he wishes I make some changes and push them to this repository. I have not worked with Git on large projects before. Is it possible to that I just make changes in the repository I am working in and keep pushing it to the main repository and Git will keep merging them? How does this work?

It's possible to do but you really need an understanding of how Git and distributed version controls work. There are several common workflows used with Git and you should check with your employer to see how they use it. Here is a basic tutorial: https://www.atlassian.com/git/tutorials/comparing-workflows/

Git pushing doesn't merge anything; it just transmits objects to the remote repository and updates branch heads. It's basically a form of file synchronization with revision awareness.

All the editing takes place locally, and so it is with Git: you do all the commit preparation, merging and so on, in your local repo. Upstream repositories cannot even do most of this stuff because they are "bare": they do not have a working tree. If you were to log into the server and enter the upstream Git repository, you wouldn't be able to do any rebasing, or merging or anything of the sort.

I'm guessing that the boss has set up the master repository as a "remote" for your local repository. Take a peek inside the .git/config file.

If everything is set up correctly, you should be able to commit to this local branch and then do a push to make the upstream branch look like the local one.

If other people have pushed something to the branch before you, you can integrate their changes with git pull --rebase , fix any conflicts and try again. The merging is all done locally.

Your push will succeed when the new changes you are pushing are based on the same parent commit which matches the upstream branch head: ie there is nothing newer upstream than the baseline you are working against. In this case, your change is a "fast-forward change".

Git detects and blocks non-fast-forward changes (meaning that newer things exist on the branch in the upstream repository which would be clobbered if your version of the branch were pushed). So when your changes are ready for publication, there is no harm in trying git push . When it doesn't work, you have to pull to integrate, and try again; the upstream doesn't do any integration.

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