# Git in a week

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXdIB2ikpHgWgXC4PKiczDYZqvcHcfQTEuaEClp3HiNfNbLJveddD2g4Q6UH5I-g2SYXyB0Cduh4yGpbxiFOcVzyhzx2kh31IV7-473jyzDgsKmbpIIKcLmxgkQ6tD_bBQOv3Rro?key=jeRUMYfRnfY9sZxCZs7yBa4E)

## Syllabus

* Version Control System & It's Types
* Git vs Github
* Git Installation and Initial Steps
* Git workflow
* project -setup
* Github account creation and Repository creation
* Git Internals
* How to link local repositories with Remote repositories
* Git operations Implementations (push, pull, clone)
* what are branches and why we use them
* Different Branching strategies
* Merge conflicts and how to fix them
* Forking vs cloning : when to use each
* what are PRs ?
* Using issues to track bugs/features
* Undoing changes (reset, revert, checkout )
* Rewrite history (ammend, rebase)
* Git Workflows (feature, develop, release, hotfix branches)
* Git Hooks
* Advanced commands (stash, cherrypick , bisect)
* Recover a deleted branch
* Synching forked repo with upstream
* Handling large files with GIt LFS
* Interview Preparation

## day 0

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfc0D58Vz4H3_DLfSWGUnsH33gyezzkLxA9GvmQIaFFZ771RPyS4XfHIyeuBaye0HGMNIkDJbZu2xk_sZoS7q14xDgjq6mjbWTanyqMyVafqPUAAZynq09hUQuEdt5uF9za4FOjkQ?key=jeRUMYfRnfY9sZxCZs7yBa4E" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXf7bnaZVZZszoQ_3p7T5YaNzp7lHYnkIj6NqSXgjA2e9q3hk2MlZWFI4dyYinuAxB3wgeeu8A5cB5X6M6xHnbBisBPO7ngk-NWFQBLoHJuGCFQgTLMhDXTL28l63k9prG0v1Vgy?key=jeRUMYfRnfY9sZxCZs7yBa4E" alt=""><figcaption></figcaption></figure>

Version Control System :&#x20;

* Version control is a system which records changes over time for a particular file/folder/codebase to recall specific versions later.

<br>

* Version Control Systems are divided into 3 types based on their place of data storage

1\. Local Version Control System

2\. Centralised Version Control System

3\. Distributed Version Control System

&#x20;    &#x20;

1. Local version Control System : programmers long ago developed local VCSs that had a simple database that kept all the changes to files under revision control.

* RCS (Revision Control System) works by keeping patch sets (that is, the differences between files) in a special format on disk; it can then re-create what any file looked like at any point in time by adding up all the patches.

<br>

2. Centralised Version Control System : To collaborate with developers on other systems, Centralised Version Control System (CVCs) are developed.

* Systems (such as CVs, Subversion, and Perforce) have a single server that contains all the versioned files, and a no.of clients that check out files from that central place

<br>

1. Distributed Version Control System : In DVCs(like Git, Mercurial or Darcs),  clients don’t just check out the latest snapshot of the files; rather, they fully mirror the repository, including its full history. Every clone is really a full backup of all the data.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXdH0gQV0G9wi8UfjjlIL0FKuY1lYfT7VhEeWOkmhKz9crwt3DqyBoclryt0p_qffDMbCfk_oOOUrSj3_sICE3jIuhvZeKZnbxfTqZ-edTCGq0QREULcUaRsVC83wCIy_zGtg-g7Nw?key=jeRUMYfRnfY9sZxCZs7yBa4E" alt=""><figcaption></figcaption></figure>

* Goals of Git creation was : Speed, simple design, strong support for non-linear development (thousands of parallel branches), fully distributed, able to handle large projects like the linux kernel efficiently (speed and data size)

Git Vs Github

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXc3-GLE2e6mOsZJiTvWT7MgFO7fZfTnA18Q4kbq2NRDGp_AtwQuhgaE4NCCliSZDbYymcRZxHoDD38AjehuRP5SZXtx-GR5jSgVOW8cep2Q0nrwezI0NidklWtag3vVXOtr1g6JEg?key=jeRUMYfRnfY9sZxCZs7yBa4E" alt=""><figcaption></figcaption></figure>

### How Git differs from other VCs ?

* The main difference between git and other vcs lies in it’s thinking about data.&#x20;

Conceptually, most other systems store information as a list of file-based changes. These other systems (CVs, subversion and so on) think of information they store as a set of files and the changes made to each file over time (this is commonly described as delta-based version control )&#x20;

* Git doesn’t think of or store its data this way. Instead, Git thinks of its data more like a series of snapshots of a small file system. With Git, every time you commit, or save the state of your project, git basically takes picture of what all your files look like at the moment and stores a reference to that snapshot
* To be efficient, if files have not changed, git doesn’t store the file again, just a link to the previous identical file it has already stored. Git thinks about it’s data more like a stream of snapshots\ <br>

Left Side (other VCs)                        Right Side (Git as a VC)

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfun_8kaYHhN2Ky_3pXcb_2oNAQJlFBDOZPUgzImmdznZibUpWvqJ71Le7MwzWzh5HmdA8JJNvvUDtGbY6G9GaVKvQvk-_YGjzhnWzRqN3nlU2hDRfvDd8lDpoKUmut4yN77Fz60g?key=jeRUMYfRnfY9sZxCZs7yBa4E" alt=""><figcaption></figcaption></figure>

* Git stores everything in its database not by filename but by the hash value of its contents<br>

* The Mechanism that git uses for this checksumming is called SHA-1. This is 40-character string composed of hexadecimal characters (0-9 and a-f) and calculated based on the contents of a file or directctory structure in Git.&#x20;

* You can’t lose information in transit (on the way to destination) or get file corruption without git being able to detect it

* Everything in git checksummed before it is stored and is then referred to by that checksum. This means it’s impossible to change the contents of any file or directory without git knowing about it.&#x20;

#### Git has Integrity :&#x20;

* Everything in git checksummed before it is stored and is then referred to by that checksum. This means it’s impossible to change the contents of any file or directory without git knowing about it.&#x20;

<br>

* You can’t lose information in transit (on the way to destination) or get file corruption without git being able to detect it

<br>

* The Mechanism that git uses for this checksumming is called SHA-1. This is 40-character string composed of hexadecimal characters (0-9 and a-f) and calculated based on the contents of a file or directctory structure in Git.&#x20;

<br>

* Git stores everything in its database not by filename but by the hash value of its contents

#### Git Workflow :&#x20;

Git has three main states that your files can reside in: modified, staged, and committed:

* Modified means that you have changed the file but have not committed it to your database yet.
* Staged (index) means that you have marked a modified file in its current version to go into your next commit snapshot.
* Committed means that the data is safely stored in your local database

The Git directory is where Git stores the metadata and object database for your project. This is the most important part of Git, and it is what is copied when you clone a repository from another computer

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXc-_bLg4qNxQw1_1wY2nfRo54BQAV0Uy1x-BCyEddVAHQ9AL8TxxnLtmL6z3GBKUPr9dasVTmsvWi6F7TYXt0_SycO2JALTAWWHhNAFNsYtHIRRAfjVeuJzFQ2jNu8Qupn3SgEGug?key=jeRUMYfRnfY9sZxCZs7yBa4E" alt=""><figcaption></figcaption></figure>

Git Installation → <https://git-scm.com/downloads>

## &#x20;<mark style="color:yellow;">**Day 1**</mark>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXeSPxznQu4E3TlzK7_a6bzbvf2Qzjv2DsQLmqwC5Tk-YYlBRm3jIM8U1PbqnR1tnYGLF_-BZxgbnQc62z_xzybEEaegK2T8KcPfSWMWliA3SIpf1iiZToU5PEt6we2lneBXlRahTg?key=jeRUMYfRnfY9sZxCZs7yBa4E" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXcyWyt1AoBozOgUDpY0Oamu013IbtwoDl3uh1vT_pnRGEJKac1tg4KAMlGSswVU2AVZJlzML4D3RS-nmktcfks7n5DaVwFKBGpOWTdbiLnXSgCXrGUveKRDfGCz3oOCKz0OoMR62A?key=jeRUMYfRnfY9sZxCZs7yBa4E" alt=""><figcaption></figcaption></figure>

<br>

* Git comes with a tool called git config that lets you get and set configuration variables that control all aspects of how Git looks and operates. These variables can be stored in three different places:
* * \[path]/etc/gitconfig
  * \~/.gitconfig or \~/.config/git/config
  * .git/config

<br>

\-   Each level overrides values in the previous level .

\- git config - - list –show-origin → To view all of our settings and where they are coming &#x20;

\- To set user name and email address, \`git conig - -global user.name “\<name>”\` and \`git config - -global user.email \<email-id>\`&#x20;

\- To check settings \`git config - -list\`

\- By default, git will create a new branch named master when we create a new repository with git init from git version 2.28 onwards.&#x20;

To set main as default branch \`git config –global init.defaultBranch main\`

<br>

* Typically, we will obtain a git repository in one of two ways :&#x20;

1. You can take local directory that is currently not under version control, and turn it into a git repository or&#x20;
2. You can clone an existing git repository from your local machine, ready for work

* To have a version control to our local folder is : first, we need to go to the directory which we wanted to make it under version control and then type git init then it will create a .git folder
* To clone a repository, we have to use git clone \<url>

<br>

* \`git status\` → To check the current status of a file
* \`.gitignore\` → To ignore set of files/folders under git tracking

To see what you’ve changed but not yet staged, type \`git diff\` with no other arguments

<br>

* Git rm, git mv, git status, git log, git - - patch, git log –stat
* Git log –pretty-online
* Git reset HEAD \<file> → To unstage a file

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXeMAib3rFRs2bF7WKy9iUAWK2AtfkvwhOAdfsQU4FBiHnvkR5haIWDSPlcqO_6VC9mRewxhfxPR0Pmna3r-_5LYeV7W4_zfltl0eucBDPnhioRBkNo9QfDc3J_QOW8I_uKmWYWVjQ?key=jeRUMYfRnfY9sZxCZs7yBa4E)![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXcXHg1AueMD6GcbxIe4G7iXKEHUefo7LeZYatCB-pMwYR5cbxLlm7oVSuw10w5cTESoaNb5LvMw2jw2GJOtmgIPtzg07BRDGzExDDJ_PHxWjqt9TTMG49levd9aFStMvk3fCaG8Ag?key=jeRUMYfRnfY9sZxCZs7yBa4E)

## Day 2

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfiXZrdlcJZpcDzzs8mD5W8UbeNIXe8SwwXw81lplnAqDX_Z34GyeAmhwk-kjK-zf7gXYONd5kQN0QQ8WkJuySChCvi9xqcAtwwwVYEY2Kn4pyHWPJxxFLrEas5QkgmLk1uSsFRxQ?key=jeRUMYfRnfY9sZxCZs7yBa4E" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfVnPu7aMZhGZ37BOUsB68lIq48GcRBwUh4hwrmJEi7_AxU7s8MPwd_zb_cvQ5Thp8CqnjQOBiZXaOgHduKZ4RK4BK4w84STSg4VO006ZpsDY5ZRkos26pQbiQVXEXvc4UZJ3oIBg?key=jeRUMYfRnfY9sZxCZs7yBa4E" alt=""><figcaption></figcaption></figure>

## Day 3

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXdVnvRCuFScM1vtDo2adFC5c3Riq_Rt6MLnuIJ_jnlNr4hptDkJQbxiUDJrM2KadNyIVN-kfR7q9dfFKuXv1AKrh2BVoHEyEEwFOoMiB-7uKvmK__C-5wyYMaFJru3ny2VtFo5ZeQ?key=jeRUMYfRnfY9sZxCZs7yBa4E" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXdKLQQnHREOM8IHvt2InzHfyPcCJATqaLw3UfwhaoFV9zTwc3I_OZSi5EBMvqLOF9L1rvsMJ4dtHs33A3vnG2aifrTmGh5HaaHyavb5CJJLbv9CA6S5cW98DvBRn3ixg7axUrux?key=jeRUMYfRnfY9sZxCZs7yBa4E" alt=""><figcaption></figcaption></figure>

## Day 4

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXcWfcaDFmglMSdIrBLj4AwMJQ11FdzAlpzHYfSikgXAN_ZeZNuWcMongD8GNU7AA51wH2tkgHFEqsG_bUdbBR5jhcV68Gg5_IQrIne5HTWr5FAgCyy_FH5D5zEgFFxpr1MP6L2JOQ?key=jeRUMYfRnfY9sZxCZs7yBa4E" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXecsebPzPKEVyZ40rw1oNBVKzLuHHJqu3OeEe5JVldwyEddyN-WSeRM9txg-qIdCSrGJtsBTU3mnKIV16j_kQvKPmjHvQjJPJMTGbXMvT_fUZTrgQMkyMVNpa8qFCeTAYBa-zYOnw?key=jeRUMYfRnfY9sZxCZs7yBa4E" alt=""><figcaption></figcaption></figure>

## Day 5

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXdoT6zSjI-zTSWlRnMFliKh9ypX2wsbkrvdZ8oIzO5tdZMt-9EgbdN9ptrtXXpsmamuEIm_VCZN4ySgIB6v6b3321u84zmxc1HO8vd1RUxwwq3592cH30avzMCdZQ-UhA6xfPXf?key=jeRUMYfRnfY9sZxCZs7yBa4E" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXeDDUc5TPLMWQCC5DJJ_r-IZnRrhjYYtX8Jl3w1KoQSmihu4scFEsJvOa0AgLJd_rLKZxyvcuWVYW-duBC_XxiU_QVg_lkW31uA426vIp_jJ5MA7O5COtmXXyFOCe1iPbct0e4aag?key=jeRUMYfRnfY9sZxCZs7yBa4E" alt=""><figcaption></figcaption></figure>

## Day 6

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXcKE1f9T9d1gAPN_cGVf4SwCXoh6X2d5TjaohltXDqQaOg1--YaJn7Fs-_VSochIJfTFst5SIYexb1FvLqKvlKJOOIEjZ5vzu9YxTTvkXHMReVsnLzQtsKo9qqyTuI1mLIZ-oylHQ?key=jeRUMYfRnfY9sZxCZs7yBa4E" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXdcnLwFCDwazWXCEoN58oQbfaEKAb6bCfP6aI3-sn61Kvgxkh2AujdbpAx6idBEeiA5bhx-UWUoDlXqLGyrR-Sxe4zqhZ2NCfOodb-J7t8jH54dOD64KBkA6upSQ8iqCi_WrfCT?key=jeRUMYfRnfY9sZxCZs7yBa4E" alt=""><figcaption></figcaption></figure>

## Day 7

## Interview Preparation


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://charan-techjourney.gitbook.io/charan-techjournal/50-days-of-devops-ecommerce-microservices/weekly-devops/git-in-a-week.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
