JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM > Git >

Setting Upstream in Git

Author:JIYIK Last Updated:2025/03/26 Views:

In this article, we will learn how to use in Git upstream. When using Git by cloning and creating new repositories in branches, we must set up upstreambranches for future commits and fetches. But first, we should understand what is upstreama branch and how it works. upstreamBranches are closely connected with remote branches.

upstreamA branch can be defined as the branch that our local branch (also called remote tracking branch) follows on the remote repository. When we need to set the default remote branch to our current local branch, we have to run git upstreamthe command.

Locally, this command is used to set up the Upstream:

git branch --set-upstream <remote-branch>

Additionally, the options mentioned below are also available:


Setting Upstream Branches with Git Push

The easiest way to set an upstream branch is to use git pushthe command with the -remote option for upstream branches -u. The following command will set a local branch to the remote branch using the branch name.

$ git push -u <remote> <branch>

Instead, you can use the -p option which is similar to -uthe -p option --set-upstream, which sets your local branch to be the remote branch.

$ git push --set-upstream <remote> <branch>

Let's take an example if we create a branchbranch called using the checkout command.

$ git checkout -b branch

It switches to a new branch branch.

--set-upstreamOne way to avoid having to type exactly is to use its short version -u, like this:

git push -u origin local-branch

This will easily set the Upstream association for any future push or pull commands. When we need to push to a remote repository and explicitly use in the command --set-upstream, it will set the branch we push to as a remote tracking branch in our local environment.

If we add a remote branch and use it in the command --set-upstream, it means Git knows what to do in the future when we do Git fetch, Git pull, or Git push. It keeps local and remote branches up to date by tracking and maintaining pull and push commands.

Previous:Staging deleted files in Git

Next: None

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Staging deleted files in Git

Publish Date:2025/03/26 Views:191 Category:Git

This article discusses the necessary steps to stage deleted files in Git. We know that the rm command can delete a file without removing it from the working directory. So, how do we stage the deleted files for commit? Staging deleted files

Git 拉取和 Git 克隆的区别

Publish Date:2024/02/04 Views:223 Category:Git

这篇简短的文章将解决 git clone 和 git pull 的区别。本教程将讨论 git clone 和 git pull 命令之间的区别。

在 Git 中添加空目录

Publish Date:2024/02/04 Views:162 Category:Git

本文深入探讨了将空 git 目录添加到 git 仓库中的方法

如何在 Windows 系统中卸载 git

Publish Date:2023/04/09 Views:878 Category:Git

在这篇简短的文章中,我们将学习如何卸载 Git,以及如何在从个人计算机的目录中卸载 Git 后删除这些文件。

如何检查 Git 的版本

Publish Date:2023/04/09 Views:270 Category:Git

在这篇检查Git最新版本的文章中,我们将学习如何在本地个人计算机或任何服务器上检查Git版本。

Git 如何重命名本地分支

Publish Date:2023/04/09 Views:121 Category:Git

大多数情况下,重命名分支机构是由于上述情况。 因此,在本教程中,我们将学习使用下面提到的技术更改本地 Git 分支的名称。

重命名 Git 存储库中的文件和目录

Publish Date:2023/04/09 Views:191 Category:Git

在本文中,我们将讨论 git 中的重命名过程。 我们使用 Git Rename 来更改工作目录中文件和文件夹的名称。

在 Git 中取消初始化存储库

Publish Date:2023/04/09 Views:365 Category:Git

本本文介绍如何通过 Git 命令行取消初始化 Git 存储库。git init 命令开发一个新的空置 Git 存储库。 它还用于重新初始化已经存在的 Git 存储库。

Git 仓库名称该如何命名

Publish Date:2023/04/09 Views:460 Category:Git

使用 Git 时,选择一个简洁且最新的存储库名称是一项艰巨的任务。本教程介绍了如何以独特的方式命名 Git 存储库。

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial