cool hit counter Git Branching: Remote Branching (2) Push, Track, Pull, and Delete_Intefrankly

Git Branching: Remote Branching (2) Push, Track, Pull, and Delete

We can use the git fetch origin command to complete the sync

Our current operations are all local. When you want to share a branch publicly, you need to push it to a remote repository. Of course you need to have write access on this remote repository

Local branches don't automatically update remote repositories - you have to actively run the push command to push local content to the branch you want to update

Use the command: git push (remote) (branch)

>>git push origin mybranch

The results of the run are as follows.

Grabbing data from the server

The next time someone else grabs data from the server, they will generate a remote branch locally

origin/mybranch, a reference to the server's mybranch branch

>>git fetch origin



One particular point to note is that running the git fetch origin command will not generate an editable copy (copy) locally.

In this case, it just generates an origin/mybranch pointer that cannot be modified locally.

That's when the local It doesn't create a new branch

So how do you merge the work on origin/mybranch to the current branch?

You can run the git merge origin/mybranch command.

How to create a local branch of your own mybranch to work on, based on the remote branch

If you want to create a local branch of your own mybranch to use for work, you can build it on top of the remote tracking branch at

>git checkout -b mybranch origin/mybranch

This will give you a local branch to work on, and the starting point will be origin/mybranch

This is the general form of the command to set up tracking branches on other remote repositories.

>>git checkout -b [branch] [remotename]/[branch]

You can set the local branch to a different name than the remote branch if you want:

Now, the local branch yourbranch will automatically pull from origin/mybranch.

View all trace branches of the setup:

If you want to see all tracked branches set up, you can use the git branch command with the -vv option

The master branch is tracking the origin/master branch and is up to date

ahead 3 (ahead 3) means that there are 3 commits locally that have not yet been pushed to the server

Behind 1 (lagging behind 1) means there is a commit on the server that has not yet been merged into the local branch

The confusing point is that the values of these numbers reflect the data you grabbed from each last grab from the server, not the state when you ran the git branch -vv command. This command does not link the remote server

Pulling data from remote servers : git fetch and git pull

When the git fetch command grabs data from the server that is not locally available, it does not modify the contents of the working directory. You need to run the git merge command to merge it yourself.

git does provide a command git pull to do both of these tasks in one step.

In most cases it means that a git fetch is immediately followed by a git merge command

Deleting remote branches

git push [remotename] --delete [branch]

For example.

>> git push origin --delete mybranch

This command removes this pointer from the server. Git servers usually hold data for a while until garbage collection runs

Today covered pushing, tracking, pulling, and deleting remote branches. Next time introduce rebase

1、Learn a little Docker every day 5 Understanding the Docker architecture
2、Talking about an alternative way to initialize a HashMap in Java
3、Remembering an NginxURIrewrite optimization
4、How to implement CSS layout
5、Google AI Curiosity and Procrastination in Reinforcement Learning

    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送