Git and GitHub 101 #2

froginacup
3 min readMar 8, 2024

--

Today’s blog post will be about navigating Git. With Git, you can know many things, including but not limited to:

  • How to download an interesting GitHub repository
  • How to visit different branches (timelines)
  • How to visit commits (specific moments in the repository’s history)

Download a remote repository to local machine

  1. Git enables us to copy code from public sources, like GitHub, GitLab etc to our own computer. It allows us to run and modify the code on our computer. To copy a repository to our machine,
git clone <uri/https>

Once you have downloaded the repository, you can open it like any normal folder on your computer.

2. Remember, most software are produced collaboratively, so it is normal to have multiple branches. To view all available branches,

git branch -a
Output of git branch -a

Let’s analyse the output.

From “*main”, we know that we only downloaded the “main” branch.

From “remotes/origin/dev” and “remotes/origin/main”, we know that in the original repository there is two branches, one called dev and another called main.

“remotes/origin/HEAD” means that the head of the branch is currently at main. We will explore this more later.

3. To explore other branches (timelines) on the repository, use

git switch <branch-name>

By default, only “master” or “main” branch is downloaded in local branch. So, in order to download the other branches, you will have to navigate to that branch.

Exploring the repository on your computer

  1. To navigate to a different branch,
git switch <branch-name>

2. To determine which branch you are on,

git branch -a
Output of git branch -a

The * indicates which branch I am on. “* dev” means that I am on dev branch. “main” means that there is another branch called “main”

I have successfully change my branch to main.

To confirm that I am on “main”,

“* main” means that I am on main. You may just ignore the “remotes/origin/”

Practice:

Some people wants practice. Here is one repo for you to explore: https://gitlab.com/collaborative-coding-with-git/code-orienteering-project-2.git

Answer these:

  1. Can you download the repository?
  2. How many branches are there?
  3. Navigate to the add-background branch. Can you do this?
  4. Confirm that you are on add-background branch.
  5. Navigate to the main branch. Can you do this?
  6. Confirm that you are on main branch

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Answers below!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

2. 4 branches.

--

--