Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Git collaboration

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

Remote warehouse

When you clone from a remote repository, Git actually automatically corresponds the local master branch to the remote master branch, and the default name for the remote repository is origin.

To view information about the remote library, use git remote:

Or, use git remote-v to display more detailed information:

It shows the address of the origin that can be crawled and pushed. If you don't have push permission, you can't see the address of push.

Push branch

To push a branch is to push all local commits on that branch to the remote library. When pushing, specify a local branch, so that Git will push the branch to the remote branch corresponding to the remote library.

$git push origin master

If you want to push other branches, such as dev, change to:

$git push origin dev

However, it is not necessary to push local branches remotely, so which branches need to be pushed and which ones do not?

The master branch is the main branch, so synchronize with the remote at all times.

The dev branch is the development branch, and all members of the team need to work on it, so it also needs to be synchronized remotely.

The bug branch is only used to repair bug locally, so there is no need to push it remotely, unless the boss wants to see how many bug you fix each week.

Whether the feature branch is pushed remotely depends on whether you work with your partner to develop on it.

Grab branch

When multiple people collaborate, everyone will push their changes to the master and dev branches.

Now, simulate one of your buddies, and you can clone from another computer (be sure to add SSH Key to GitHub) or under another directory on the same computer:

When your partner clone from the remote library, by default, your partner can only see the local master branch

Now, if your buddy wants to develop on the dev branch, he must create a remote origin dev branch locally, so he uses this command to create a local dev branch:

$git checkout-b dev origin/dev

Now he can continue to modify it on dev, and then push the dev branch remotely from time to time:

Your buddy has pushed his submission to the origin/dev branch, and it so happens that you have made changes to the same file and tried to push

The push failed because there is a conflict between your partner's latest submission and the one you are trying to push, and the solution is simple. Git has prompted us to grab the latest submission from origin/dev with git pull, and then merge locally, resolve the conflict, and then push:

Git pull also failed because the link between the local dev branch and the remote origin/dev branch was not specified. As prompted, set the link between dev and origin/dev

Then pull:

Git pull is successful this time, but there are conflicts in the merger, which need to be resolved manually, in exactly the same way as in branch management. After resolution, submit, and then push:

Fetch and pull

There are two commands that can be used to get data from the remote branch of the server, in addition to the pull command used above, there is also the fetch command

Git fetch origin synchronizes the data of the master branch on the remote server origin to the local

Using the fetch command, you only download the origin data locally, but the local working directory can only be updated to the latest content by using merge merge.

$git merge origin/master merges the remote branch master on the remote server to the local branch master

If you use the pull command, it is equivalent to the combination of the fetch and merge commands

Git pull origin synchronizes the data of the master branch on the remote server origin to the local and merges it to the local branch master

If it is not the default master branch, but other branches, such as the dev branch, you can use the

$git pull origin dev

Equivalent to

$git fetch origin dev$ git merge origin/dev

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report