Cover photo by Yolanda Sun
So, I've seen a lot of folks experience this issue while collaborating with software developers on GitHub.
The issue: git remote add upstream [remote-repository-url] and git pull upstream [branch-name].
Let's get to why we need to use the aforementioned commands in the terminal. You are working on a project with your team on GitHub which for sure, they would have a repository that you will be pushing to, pulling, and reviewing codes from. The common thing to do at first is to fork the repository so you can get a copy of the repository.
Issue #1: git remote add upstream [remote-repository-url]
When you type git remote add upstream [remote-repository-url]
into your terminal, what you're simply telling git is this: "Oh hey there git, kindly help me by adding this remote repository as the original version of my forked repository" and git responds with an empty confirmatory message. git stores that remote repository link that you've provided for it in the terminal, somewhere.
You can think of it as also like storing a value of something in a variable in your preferred programming language, and then retrieving it when you need it in the future.
const upstream = "https://github.com/dummy-user/example-repo.git/"
Issue #2: git pull upstream [branch-name]
Now that git already stored our remote repository in our "assumed" variable, upstream
. Pulling from a repository is the same thing as getting new changes from a repository after we've cloned it, reason being that the repository will keep getting updates from the team as they add more codes to it.
Referring to our little snippet above. Since you've already assigned the repository's link to the upstream
variable, what you need to do is just type the command git pull 'upstream'
const upstream = "https://github.com/dummy-user/example-repo.git/"
console.log(upstream)
When you add no branch-name after upstream
it pull from the default branch, which is master. When you add a branch name after it, it brings or gets the information(codes from that branch).
i.e. git pull upstream [branch1]
const upstream = {
url: "https://github.com/dummy-user/example-repo.git/",
branches: {
branch1: "value",
branch2: "value",
branch3: "value"
}
}
console.log(`${upstream.url}${upstream.branches.branch1}`)
// https://github.com/dummy-user/example-repo.git/value
Thank you for reading. If this article has helped you understand something, kindly share it among your pals and please do not hesitate to drop your feedbacks in the comments below.