Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code: What is the difference between push and publish

On the GIT tab in Visual Studio Code there is an context menu with these items:

  • Sync
  • Pull
  • Pull (release)
  • Push

==================

  • Publish

==================

...

What does the publish button do?

like image 961
Liero Avatar asked May 06 '16 14:05

Liero


People also ask

What does publish branch do in VS Code?

Allows you to choose which remote you want to push to.

What does publish branch mean?

A local branch that you create on your machine is kept private to you until you explicitly decide to publish it. This means that it's perfectly possible to keep some of your work private while sharing only certain other branches with the world.

What is publish in git?

If you want to push to, pull from, or synchronize using a branch you have created, you must publish the branch. You can still commit to an unpublished branch, but until you publish, you will not be able to send your commits to source control for backup.

What is push in Visual Studio?

Push from Visual Studio to a remote branch One of those improvements is the ability to push (also known as publishing) a local project straight to GitHub with a single click. The final stage in a simple Git workflow is to push changes to your remote. A remote is a safe place to store your code in the cloud.


2 Answers

After checking the source code of Visual Studio Code.

Push

Push the current branch to the default remote upstream

public run(context?: any):Promise {
    return this.gitService.push() // ... removed for brevity        
}

Active when:

There is UPSTREAM and recent push/pulls (ahead)

if (!HEAD || !HEAD.name || !HEAD.upstream) {
    return false;
}

if (!HEAD.ahead) { // no commits to pull or push
    return false;
}

Publish

Allows you to choose which remote you want to push to.

public run(context?: any):Promise {
        const model = this.gitService.getModel();
        const remotes = model.getRemotes();
        const branchName = model.getHEAD().name;
        let promise: TPromise<string>;

        if (remotes.length === 1) {
            const remoteName = remotes[0].name;
            promise = TPromise.as(result ? remoteName : null);
        } else {
            // open the option picker            
            promise = this.quickOpenService.pick(picks, { placeHolder })
                .then(pick => pick && pick.label);
        }

        return promise
            .then(remote => remote && this.gitService.push(remote, branchName, { setUpstream: true }))            
}

Active when

There is NO UPSTREAM and off course remote branches are set.

if (model.getRemotes().length === 0) {
    return false;
}

if (!HEAD || !HEAD.name || HEAD.upstream) {
    return false;
}
like image 51
amd Avatar answered Oct 04 '22 23:10

amd


From the docs:

If there is no upstream branch configured and the Git repository has remotes set up, the Publish action is enabled. This will let you publish the current branch to a remote.

So I'd expect that if you have an upstream branch configured, you would be able to Push (i.e. push directly to the configured upstream branch) and if you have no upstream branch configured you are only allowed to Publish (i.e. select a remote and branch to push at).

like image 42
eckes Avatar answered Oct 04 '22 23:10

eckes