Decoding Git: A Deep Dive into its Internal Workings and Architecture

Опубликовано: 30 Октябрь 2024
на канале: The Tech Eye
18
1

Git is a version control system, and its primary purpose is to manage changes to files and #projects over time. #versioncontrol allows multiple developers to #work collaboratively, track changes, and revert to previous versions if necessary. Git is a #distributedsystem , which means that you can work on your project offline. When you connect to the internet again, Git will synchronize your local copy of the repository with the remote repository. This means that you can work on your project from anywhere, and you don't have to worry about losing your changes.It's a very powerful tool, and it's used by millions of #developers around the world.

You can download #git from https://git-scm.com/

Check the Git version with command git --version

So, how does #Git work?
At its core, Git is a #database of snapshots. Every time you make a change to your #code , Git takes a #snapshot of your project. This snapshot includes the contents of all your files, as well as the metadata about those files, such as the author, the date, and the commit message.
It's essential to identify where our code is stored. The common assumption is that there are only two locations - one on a #remoteserver like #github and the other on our local machine. However, this isn't entirely accurate. Git maintains three local #storages on our machine, which means that our code can be found in four places:
Working directory
The working directory is the directory in which you are currently working. The working directory is where you will be editing your files.
Staging area
The staging area is a temporary location where files are kept for the next commit.
Local repository
The local repository is the central location where Git stores all of your data.
Remote repository
The remote repository is a #repository that is hosted on a server.
Now lets go through some common Git commands that you can use to operate between these areas:
The first step to using Git is to initialize a Git repository. This can be done by running the following command in your project directory:
git init.
Once you have initialized a #Gitrepository , you can start making changes to your code. When you make a change to a file, Git will add the file to the staging area. The staging area is a temporary area where Git stores files that are about to be committed. To add a file to the staging area, run the following command: git add [file name]
Once you have added all the files that you want to commit, you can commit your changes. Committing your changes creates a snapshot of your project. This snapshot includes the contents of all the files in your staging area, as well as the metadata about those files. To commit your changes, run the following command: git commit -m "[commit message]" The -m flag is used to specify the commit message. The #commit message is a brief description of the changes that you have made.
Once you have committed your changes, you can push them to a remote repository. A remote repository is a repository that is hosted on a server.
To push your changes to a remote repository, run the following command: git push [remote name] [branch name]
You can also pull changes from a remote repository. Pulling changes brings the changes from the remote repository into your local repository.
To pull changes from a remote repository, run the following command:
git pull [remote name] [branch name]

The git clone command is used to create a copy of an existing Git repository.
The git checkout command is used to switch to a different branch or to a specific commit. The syntax for the git checkout command is as follows: git checkout [branch name]
Some other useful commands are
git init : This command initializes a new Git repository. This is the first command you need to run if you want to start using Git.
git status : This command shows the status of your working directory and the staging area.
git log : This command shows the history of your commits.
git diff : This command shows the differences between two commits or between your working directory and the staging area.
git reset : This command resets your working directory to a previous commit.
To create a new branch, run the following command: git branch [branch name]

📚 RESOURCES
Official Git web site: https://www.git-scm.com/
Official GitHub.com web site: https://github.com/
Git and GitHub.com cheat sheet: https://education.github.com/git-chea...
Git Reference Manual: http://git-scm.com/docs
Git Overview Book: http://git-scm.com/book/en/v2
Sample ignore files: https://github.com/github/gitignore

⌚ Key Moments
00:00 Introduction
01:01 How Git Works internally?
02:57 Git's Basic Workflow Lifecycle
08:55 Understanding Merge Conflicts
09:40 Common Git Commands


HashTags
#coder #programming #softwaredevelopment #computerscience #softwaredeveloper #github #githubactions #git #gitcourse #gitcommands #gitcrashcourse #viral #tutorials #tutorial #gittutorial #githubtutorial