search
HomeDevelopment ToolsgitTeach you how to set different fetch and push addresses in Git

The Git Tutorial column of this article will introduce to you how to set different fetch and push addresses in Git. Friends in need can collect and learn~ I hope it will be helpful to everyone.

Under normal circumstances, if you are developing with Git alone, you do not need code review or anything like that. One address for fetch and push is enough. Anyway, there is no need for review, and no one will cover your code.

But in the company, or in the formal code merging process, there will be a review link, which is probably:

  • fork the main warehouse to the personal warehouse

  • clone personal warehouse to local

  • Modify local code and submit commit

  • push modify to personal warehouse

  • Submit Merge Request to the main warehouse

If there are changes in the main warehouse, another step is required:

  • Synchronous changes from the main warehouse, that is, manual pull

So, how to set the personal warehouse as the push address and the main warehouse as the pull address?

Method 1: Multiple origins

The first method is to add another address to the original origin remote warehouse address, which is the main warehouse address. For example, add an origin_mian as follows:

git remote add origin_main git@github.com:yeszao/dnmp.git

In this way, we have configured a total of 4 addresses, 2 push and 2 pull:

git remote -v

origin git@github.com:MY_REPOSITY/dnmp.git (fetch)
origin git@github.com:MY_REPOSITY/dnmp.git (push)
origin_main git@github.com:yeszao/dnmp.git (fetch)
origin_main git@github.com:yeszao/dnmp.git (push)

When pushing and pulling the code, you can do this:

git push origin master
git pull origin_main master

Method 2: One origin (recommended)

Another way is that we only use one origin, set the main warehouse to the fetch address, and the personal warehouse to the push address:

git remote set-url origin git@github.com:yeszao/dnmp.git
git remote set-url --add --push origin git@github.com:MY_REPOSITY/dnmp.git

Use the git remote command to see the configured address:

origin git@github.com:MY_REPOSITY/dnmp.git (push)
origin git@github.com:yeszao/dnmp.git (fetch)

This way it is very simple to push and pull the code:

git push origin master
git pull origin master

If there are no special requirements, it is recommended to use method two , usage and commands are simpler.

The above is the detailed content of Teach you how to set different fetch and push addresses in Git. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:awaimai. If there is any infringement, please contact admin@php.cn delete
GitHub's Purpose: Version Control, Collaboration, and MoreGitHub's Purpose: Version Control, Collaboration, and MoreApr 27, 2025 am 12:05 AM

GitHub is not just a version control tool, it also provides collaboration, project management and community communication capabilities. 1) Version control: Use Git to track code changes. 2) Collaboration: Submit code changes through PullRequest. 3) Project management: Use Issues and Project sections to manage tasks. 4) Community communication: Learn and communicate through fork and participating in open source projects.

GitHub vs. Git: Understanding the Key DifferencesGitHub vs. Git: Understanding the Key DifferencesApr 26, 2025 am 12:12 AM

Git and GitHub are different tools: Git is a version control system, and GitHub is an online platform based on Git. Git is used to manage code versions, and GitHub provides collaboration and hosting capabilities.

GitHub: Code Hosting, Collaboration, and Version ControlGitHub: Code Hosting, Collaboration, and Version ControlApr 25, 2025 am 12:23 AM

GitHub is a distributed version control system based on Git, providing the core features of version control, collaboration and code hosting. 1) Creating repositories, cloning, committing and pushing changes is the basic usage. 2) Advanced usage includes using GitHubActions for automation, deploying static websites in GitHubPages, and using security features to protect code. 3) Common errors such as merge conflicts, permission issues and network connection issues can be debugged by manually resolving conflicts, contacting the warehouse owner and setting up a proxy. 4) Methods to optimize workflows include using branching strategies, automated testing and CI/CD, code review, and keeping documentation and annotations clear.

Git: The Tool, GitHub: The ServiceGit: The Tool, GitHub: The ServiceApr 24, 2025 am 12:01 AM

Git and GitHub are different tools: Git is a distributed version control system, and GitHub is an online collaboration platform based on Git. Git manages code through workspaces, temporary storage areas and local warehouses, and uses common commands such as gitinit, gitclone, etc. GitHub provides functions such as code hosting, PullRequest, IssueTracking, etc. The basic process includes creating repositories, pushing code, and collaborating with PullRequest.

Git: The Core of Version Control, GitHub: Social CodingGit: The Core of Version Control, GitHub: Social CodingApr 23, 2025 am 12:04 AM

Git and GitHub are key tools for modern software development. Git provides version control capabilities to manage code through repositories, branches, commits and merges. GitHub provides code hosting and collaboration features such as Issues and PullRequests. Using Git and GitHub can significantly improve development efficiency and team collaboration capabilities.

Git: The Version Control System, GitHub: The Hosting PlatformGit: The Version Control System, GitHub: The Hosting PlatformApr 22, 2025 am 12:02 AM

Git is a distributed version control system developed by Linus Torvaz in 2005, and GitHub is a Git-based code hosting platform founded in 2008. Git supports branching and merges through snapshot management files, and GitHub provides pull requests, problem tracking and code review functions to facilitate team collaboration.

Git and GitHub: A Comparative AnalysisGit and GitHub: A Comparative AnalysisApr 21, 2025 am 12:10 AM

Git and GitHub are key tools in modern software development. Git is a distributed version control system, and GitHub is a Git-based code hosting platform. Git's core features include version control and branch management, while GitHub provides collaboration and project management tools. When using Git, developers can track file changes and work together; when using GitHub, teams can collaborate through PullRequests and Issues.

GitHub: An Introduction to the Code Hosting PlatformGitHub: An Introduction to the Code Hosting PlatformApr 20, 2025 am 12:10 AM

GitHubiscrucialforsoftwaredevelopmentduetoitscomprehensiveecosystemforcodemanagementandcollaboration.Itoffersversioncontrol,communitysupport,andtoolslikeGitHubActionsandPages.Startbymasteringbasicslikecreatingarepository,usingbranches,andautomatingwo

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.