From 9a9f3a95f19d67d45f0867acb6622bbe4705b6d0 Mon Sep 17 00:00:00 2001
From: Mactavish <maczhanchao@yahoo.com>
Date: Sun, 23 Apr 2023 20:49:00 +0200
Subject: [PATCH] add tracking branches

---
 git.md | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/git.md b/git.md
index 810ab9e..ef36876 100644
--- a/git.md
+++ b/git.md
@@ -323,6 +323,26 @@ git checkout -b <new branch name>
 git checkout -b <new branch name> <some other exisiting branch>
 ```
 
+#### Tracking Branches
+
+Lets say you are working on a branch named `dev` which you fetched from the remote named `origin`. Now you want to work on this branch for a quite a long time and want the `git push` and `git pull` using the `dev` branch of `origin` by default. So that you won't have to type `git push origin dev` or `git pull origin dev` every time you want to update or pull the updates to and from the remote branch.
+
+First, you need to tell Git which branch to track:
+
+```c
+# suppose you are on the dev branch on you local machine, and there is already a dev branch in the remote repo
+git branch --set-upstream-to origin/remote
+```
+
+This only works when there is already a `dev` branch in the remote repo. If you want to create a new branch in the remote repo, and track it automatically, then you can use the following command:
+
+```
+# this will create a dev branch in the remote and track it using the current branch locally
+git push --set-upstream origin dev
+# or, same as above
+git push -u origin dev
+```
+
 #### Merging Branches
 
 Merging in Git is the way to putting forked history back together again. The `git merge` command lets you integrate branches created by `git branch` into a single branch.
-- 
GitLab