[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-11。"],[],[],null,["# Pushing code from an existing repository\n\nThis topic describes how to push code from an existing repository on your local\nmachine to Cloud Source Repositories.\n\nBefore you begin\n----------------\n\nYou must have a repository in Cloud Source Repositories. To create a\nrepository, see\n[Creating an empty repository](/source-repositories/docs/creating-an-empty-repository).\n\nPush a local repository into Cloud Source Repositories\n------------------------------------------------------\n\nYou can push a local repository to Cloud Source Repositories by using either\nSSH, the Google Cloud CLI, or manually generated credentials. \n\n### SSH\n\n1. Ensure you have\n [set up local authentication](/source-repositories/docs/authentication#ssh)\n with SSH.\n\n2. Add your local repository as a remote:\n\n git remote add google ssh://[EMAIL]@source.developers.google.com:2022/p/[PROJECT_ID]/r/[REPO_NAME]\n\n Where:\n - `[EMAIL]` is your Google Cloud username.\n - `[PROJECT_ID]` is the ID of the Google Cloud project where the repository is located.\n - `[REPO_NAME]` is the name of the repository.\n\n For example: \n\n git remote add google ssh://user@gmail.com@source.developers.google.com:2022/p/example-project/r/test-repo\n\n3. Push your code to Cloud Source Repositories:\n\n git push --all google\n\n### gcloud CLI\n\n1. Ensure that\n [the gcloud CLI is installed](/source-repositories/docs/authentication#authenticate-using-the-cloud-sdk) on your machine.\n\n2. Open a terminal window.\n\n3. If you're using Windows, enter the following command:\n\n gcloud init && git config credential.helper gcloud.cmd\n\n If you're using Linux or macOS, enter the following command: \n\n gcloud init && git config credential.helper gcloud.sh\n\n4. Add your local repository as a remote:\n\n git remote add google \\\n https://source.developers.google.com/p/[PROJECT_NAME]/r/[REPO_NAME]\n\n Where:\n - `[PROJECT_NAME]` is the name of your Google Cloud project.\n - `[REPO_NAME]` is the name of your repository.\n5. Push your code to Cloud Source Repositories:\n\n git push --all google\n\n### Manual\n\n1. Ensure you have\n [generated and stored your Git credentials](/source-repositories/docs/authentication#manually-generated-credentials).\n\n2. Open a terminal window and add your local repository as a remote:\n\n git remote add google \\\n https://source.developers.google.com/p/[PROJECT_NAME]/r/[REPO_NAME]\n\n Where:\n - `[PROJECT_NAME]` is the name of your Google Cloud project.\n - `[REPO_NAME]` is the name of your repository.\n3. Push your code to Cloud Source Repositories:\n\n git push --all google\n\nUse the repository as a remote\n------------------------------\n\nGoogle Cloud repositories are fully featured Git repositories. You can use\nthe standard set of Git commands to interact with these repositories, including\n`push`, `pull`, `clone`, and `log`.\n\n### Push to a Google Cloud repository\n\nTo push from your local Git repository to a Google Cloud repository, enter\nthe following command: \n\n git push google master\n\n### Pull from a Google Cloud repository\n\nTo pull from a Google Cloud repository to your local Git repository, enter\nthe following command: \n\n git pull google master\n\n### View the commit history of a Google Cloud repository\n\nTo view the commit history, enter the following command: \n\n git log google/master\n\nWhat's next\n-----------\n\nAfter you push your local repository to your local machine, you can:\n\n- [Learn from your code's history](/source-repositories/docs/history-overview).\n- [Search your code](/source-repositories/docs/searching-code)."]]