Towards AI

The leading AI community and content platform focused on making AI accessible to all. Check out our new course platform: https://academy.towardsai.net/courses/beginner-to-advanced-llm-dev

Follow publication

Member-only story

All About Git Branches... And Git pull vs. fetch

Muttineni Sai Rohith
Towards AI
Published in
5 min readDec 24, 2022

--

With Branches in Git, we can create a copy of the file we would like to work on without messing up with the original file. Later we can merge them to the original copy.

This is the second addition to the series of articles about Git — Complete Git Tutorial for Beginners with Examples. The link is available below —

So far, we have created the main branch, pushed our first commit to the branch, and then 2nd commit. Our repo looks like this —

To clone a specific branch, use this command in git bash

git clone -b <branchname> <remote-repo-url>

Now let's create a test branch and push our new changes to that branch. We can create a new branch named “test” using the below command -

git checkout -b test

In the above command, checkout makes us switch to a branch, and -b helps us in creating the branch.

Now Let’s add some changes, then add them to our local repo commit and push them to the remote repo with the test branch.

def add(a, b):
return a+b+10

We can add, commit and push changes to the remote repo using the following commands —

git add .
git commit -m “Updating the add function with offset 10”
git push origin test

Instead of git add . and git commit -m “message” we can use the following command —

git commit -am "Updating the add function with offset 10"
git push origin test

Now our repo looks like this -

Branch Flow

Now Let’s make another change by changing the offset to 20 and commit and push to the test branch again.

def add(a, b):
return a+b+20

Let’s add, commit and push into the remote Repo

git commit -a -m "changing the offset to 20"
git push origin test

--

--

Published in Towards AI

The leading AI community and content platform focused on making AI accessible to all. Check out our new course platform: https://academy.towardsai.net/courses/beginner-to-advanced-llm-dev

Written by Muttineni Sai Rohith

Senior Data Engineer with experience in Python, Pyspark and SQL! Reach me at sairohith.muttineni@gmail.com

No responses yet

Write a response