A Comprehensive Guide to Git and Github: Understanding Version Control Systems, Exams of Advanced Education

This document offers a detailed explanation of git and github, covering fundamental concepts such as version control, object types (blob, tree, commit, annotated tag), hash functions, staging area, commits, branches, merging (fast-forward and 3-way), remote repositories, and tags. it's structured as a q&a, making it an excellent resource for learning and reinforcing understanding of these crucial tools for software development. The guide includes practical examples and commands, enhancing its educational value.

Typology: Exams

2024/2025

Available from 05/05/2025

Smartsolutions
Smartsolutions 🇺🇸

3

(4)

18K documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Github Study Guide With
Complete Solution
Git vs Github - ANSWER Git is a Distributed Version Control System that
helps to track the changes in the source code. Git is simply a persistent hash
map wherein key is the hash of file and the value is the contents of the file.
Github is used to manage the remote repository. If you wanna use Git you
must install in your local machine.
cat command - ANSWER Allows us to create to create single or multiple files,
view contain of file, and concatenate files and redirect output in terminal or
files
nano - ANSWER edit the file using this shell command
what does git init do? - ANSWER creates the git repository and places the
hidden .git folder within the git repository
how to view hidden folders in finder - ANSWER command + shift + .
what are the four object types in git - ANSWER Blob, tree, commit, annotated
tag
what is blob - ANSWER It is an object type for git. Binary large object => Its
the object type used to store contents of each file in a repository (file data)
tree - ANSWER It's an object type for git. It stores information about
directories. In other words, it's just like a directory - it references bunch of
other trees and/or blobs, i.e. files and sub-directories
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download A Comprehensive Guide to Git and Github: Understanding Version Control Systems and more Exams Advanced Education in PDF only on Docsity!

Github Study Guide With

Complete Solution

Git vs Github - ANSWER Git is a Distributed Version Control System that helps to track the changes in the source code. Git is simply a persistent hash map wherein key is the hash of file and the value is the contents of the file. Github is used to manage the remote repository. If you wanna use Git you must install in your local machine.

cat command - ANSWER Allows us to create to create single or multiple files, view contain of file, and concatenate files and redirect output in terminal or files

nano - ANSWER edit the file using this shell command

what does git init do? - ANSWER creates the git repository and places the hidden .git folder within the git repository

how to view hidden folders in finder - ANSWER command + shift +.

what are the four object types in git - ANSWER Blob, tree, commit, annotated tag

what is blob - ANSWER It is an object type for git. Binary large object => Its the object type used to store contents of each file in a repository (file data)

tree - ANSWER It's an object type for git. It stores information about directories. In other words, it's just like a directory - it references bunch of other trees and/or blobs, i.e. files and sub-directories

commit - ANSWER Its an object type that allows to store different versions of the project

annotated tag - ANSWER object type, which is a persistent pointer that points to different commits

What does a hash function do? - ANSWER Generates a fixed length hash based on the input. Same input will have the same hash. One way function. Cannot get input based off hash. Only hash based off input

git hash-object - ANSWER allows us to create a new blob object type

sha1 bit size? - ANSWER 160 bits

how to create hash from string in command line ANSWER echo "Hello Git" | shasum

what is the probability of reaching a specific hash given a file ANSWER 1/(2^160) => There are 2^160 possible options for SHA1 (160 bits)

git cat-file options ANSWER - git cat-file -p => contents of the object

  • git cat file -s => size of the object
  • git cat file -t =>type of the object

how to git the hash of the a file or object using pipe - ANSWER echo "Hello, Git" | git hash-object --stdin -w

--stdin => take input from standard input

  • w => create git object

how would you write a string to a new file - ANSWER echo "Hello Git" >

and git blob, which acts as a wrapper around the git tree. It contains a pointer to a specific tree. The fields that git commit contains are: author name, email, commit description, parent, hash, and the pointer-hash of the tree that it's wrapping. The commit of files in the staging area to the git repository-the files stay in the staging area. You are finally writing to the git repository changes.

how to set name and email of the the git commit - ANSWER git config --global user.name

git config --global user.email

can use git config --list to see the name and email of the git commit

what is a root commit? - ANSWER The first commit made in the project. Does not have any parent commits

git status - ANSWER current state of the git repository. Shows untracked and modified files.

git log - ANSWER history of changes of the git repository

git checkout - ANSWER checkout commit or branch. Files are taken from git repo and placed in working directory

what are the four different status of each file - ANSWER 1. untracked

  1. modified
  2. staged
  3. unmodified

when you git add. the file is now being staged (meaning its being tracked) untracked => modified.

This is a file whose time line of modification, staging, and unmodified are kept track of.

git commit - ANSWER changes the file from staged to unmodified

git rm --cached - ANSWER take file from staged to working directory. Changes the status from staged to untracked.

untracked <= modified <= staged

Why does the root tree hash change when you add a new commit? ANSWER Because the contents and the size of the tree change so the tree objects can't be the same because of the changes that have happened. Also the hash will change.

to the file then quit press ":wq"

detached HEAD? - ANSWER when the commit is pointing to a specific commit and not a branch

delete brnch - ANSWER git branch -d

rename branch - ANSWER git branch -m

creating a branch and checking it out at the same time - ANSWER git branch -b

if you create a feature branch will it have the same sha? - ANSWER Yes because at that point in time it is referring to the same commit

how to find the contents of the HEAD - ANSWER cat .git/HEAD

how to structure git diff - ANSWER git diff --old-file new-file

If you want to "git cat-file -p" the "new-file" make sure the "new-file" is committed. Then the actual blob will be in the .git repo.

The default of "git diff" takes the uncommitted changes as the "new-file".

fast forward merge - ANSWER If there are no additional merges on the master branch then all that is simply done is that the HEAD/master pointer is moved to the last commit on the feature branch.

After that you can delete the feature branch

When performing merge you must checkout the receiving branch (main branch) then "git merge feature-branch"

git branch -d BR-

The fast-forward merge happens when the receiving branch has no extra commit after the creation of the new branch.

What is the difference between 3-way merge and fast forward merge? ANSWER 3 way merge occurs when additional commits are taking place after the creation of a new branch.

It's much more than just moving to the latest commit pointer on the feature branch.

Instead, a new commit is made to the master branch which points to both the latest commit on the feature and master. So, when you delete the feature

git remote show origin ANSWER - shows the links between local and remote repository from a branch perspective

git pull ANSWER - git pull is a two step process. First you git fetch( remote changes => local branch) then merges into your working directory. It only updates the currently checkout branch.

FETCH_HEAD file - ANSWER The FETCH_HEAD file indicates which branch will be merged, and which will not. By default the current branch will be the one to merge when typing git pull. FETCH_HEAD basically is the remote branch that will be merged to the local branch when a git pull is executed-second step. First is git fetch is peformed, then git merge "FETCH_HEAD is called second.

how to find the contents fo the config - ANSWER cat .git/config

how to show remote branches - ANSWER git branch -r

how to delete remote branch - ANSWER git push origin -d <branch-name>

git branch -d <branch-name> only deletes the branch locally

how to track locally newly made branch to remote branch - ANSWER git push -u origin <branch-name>

git command to show references - ANSWER git show-ref

what is tag in git - ANSWER it is a static text pointer to a particular commit, whereas a branch pointer is dynamic is moved to the latest commit on that branch

git tag - ANSWER shows list of tags created

creating a light weight tag - ANSWER git tag <tag-name>

where to view sha1 where the lightweight tag is pointing too - ANSWER .git/ref/tags/<tag-name>

How to change where the tag points to - ANSWER git tag --force v1. <ID-of-commit-127>

git push --force --tags

how to push tags to the remote repo - ANSWER git push --tags

steps of rebasing - ANSWER 1. checkout out feature branch: git checkout