How can you check out remote branches in Git? You don't. Even though the git switch command is the preferred way of doing that since version 2.23, you can still switch branches by running git checkout. You can use the git checkout command for a variety of tasks, including switching to another branch. Just run git remote -v and you'll get a more detailed view, featuring the URLs for fetching and pushing data (which are, by default, the same): Using the "Git Checkout" Command To Check Out a Non-Remote Branch The remote command also has a verbose option. It doesn't have any special meaning, though, and you can change it to any valid Git name. "Origin" in Git is a convention for the name of the default remote. If everything works fine, you should see the word "origin" as a result. You can then use your terminal to access the folder and then ask Git about your remotes: To clone that repository (that is, make a local copy for you), you'd do this:Īfter running the command above, you'll have a folder called liteguard. A Quick Exampleįor instance, let's say you're browsing through GitHub and you come across a nice open-source project. You might have read access to a remote while having read and write access to others. You collaborate with other people by pulling changes from and pushing changes to these remotes. For any repository, you can have as many remotes as you like. You can think of remotes as copies of your project that are hosted somewhere else: They can be stored on a coworker's machine or a server in your local network, or they can be hosted on services like GitHub. What it does have are remote repositories, often called simply remotes. So how do you collaborate with others when working on a team? No Central Server in Gitīecause Git is a decentralized tool, it lacks the concept of a central server. When you're working with Git, what you have locally is not a mere working copy, like in centralized tools, but rather a real, full repository. After the work is done, the developer sends their changes to the central server, where they are incorporated into the code. When it's time to start working on something, a developer gets the code from the server to their local machine, where they have a working folder. Centralized VCSs Have a Central ServerĬentralized version control tools, like Subversion, have the concept of a central server that stores the repositories. Let's now understand the role that remotes play in Git and how that differs from the approaches taken by centralized source control tools. For newcomers that were previously users of such tools like Subversion or TFVC, groking remotes and remote branches might take some serious unlearning. But the way in which Git's design chooses to handle collaboration is radically different from the approaches used in most other traditional centralized version control tools. Not because remotes are a particularly hard concept-they aren't. Git Remotes: An Introductionįor newcomers to Git, the way remotes work is in fact one of its most troublesome traits. Finally, we'll show you several ways in which Git makes it possible to work with remote repositories. Then we'll talk about the checkout command, showing how you can use it to check out non-remote (that is, local) branches. We'll begin with an overview of what remotes are and how they work in Git. How do you perform a Git checkout on a remote branch? In this post, we'll answer that question in detail.
0 Comments
Leave a Reply. |