Reputation: 680
I added my files and commited with no problem. The problem is that when I press "Publish to Github" the only options there appear are private and public repositories as individual. But I would like to publish as an organization.
Upvotes: 53
Views: 21427
Reputation: 2729
I initialized the repository and tried adding via VS Code's 'Git: Add Remote`, but I got an error:
So I just wanted to point out that the command line is always there. Open the terminal, navigate to the root dir of the repo and:
git remote add origin https://github.com/YourOrganization/YourRepo.git
That worked for me with no issue.
Upvotes: 1
Reputation: 467
The built-in VS Code GitHub extension does not currently (in 2024) have the ability to publish a local repository to an organization.
But you can easily create an organization repository from a local copy using the GitHub CLI.
gh repo create organization-name/repo-name --source . [--private|--public|--internal]
--source string
- Specify path to local repository to use as source
--internal
- Make the new repository internal
--private
- Make the new repository private
--public
- Make the new repository public
Most modern popular Linux distros have an official GitHub CLI in their system package repository, so you can install it using your favorite package manager. The GitHub CLI package is usually called gh
or github-cli
.
macOS has gh
package in brew
.
On Windows you can install GitHub CLI with release files from the official GitHub CLI repository.
Upvotes: 1
Reputation: 601
By default, GitHub allows you to publish to your own public or private repositories. To publish to an organization repository, follow the steps below -
Create an organization repository in GitHub, if not already created.
Press "Initialize Repository" in VS Code's "Source Control" and commit the code.
Open the Command Palette in VsCode by clicking Ctrl+Shift+P, select "Git: Add Remote", and paste your organization's repository URL. You can also open the "Source Control" tab, go to the Remotes section, click the plus sign, and paste the URL of your organization's repository.
This should add the repository as a remote. This enables you to push the code to your organization's repository.
Handling Errors - Sometimes we may get errors like "failed to push some refs to...". This occurs when your local repository hasn't been updated with the changes in the remote repository. To fix this error, open the terminal and execute the following commands -
git pull --rebase origin main
git push -u origin main
NOTE- The origin
in the above command refers to the organization repository's URL.
If the first command is successful, you should get a response 'Successfully rebased and updated refs/heads/main'
Now whenever you push/pull any code, it will update seamlessly to/from the organization's repository.
Upvotes: 4
Reputation: 86
Github Desktop allows you to choose the organization to publish. Just click the "publish repository" and choose the organization to publish at the bottom list.
Upvotes: 3
Reputation: 217
I just wanted to add another workaround as I came across the same issue.
Upvotes: 13
Reputation: 7236
Workaround for the lack of functionality:
You can add your project to a local repository by pressing "Initialize Repository" in your "Source Control" tab.
After that, go to Github and make a new empty organisation repository.
Now you can hit F1 and type "Add Remote". You can now choose "Git: Add remote..." and then paste the repository's URL, instead of adding from Github.
Now committing and pushing should work as expected.
Upvotes: 43