Search code examples
gitvisual-studio-code

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?


Solution

  • 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;
    }