Creating a repository in Git
I'll be discussing the version control tool Git in this article. What has now happened is that we have made Git complicated because we obviously don't understand the basics of this technology. We just use git push and git pull. It occasionally works, however, the majority of the time we get merge conflicts and become stuck. This was the situation for me, at least.
Source: Safalta.comSo I made the decision to finally understand this incredible tool, and that made everything apparent. So let's begin. Click here to enrol and learn from the digital marketing course.
Between Git and Github, there is now a distinction. GitHub is a service that hosts Git projects, allowing developers to seamlessly communicate while working on a project. Git is a version control tool.
Download these FREE Ebooks:
1. Introduction to Digital Marketing
2. Website Planning and Creation
There are two basic categories for version control systems. The centralised model is one, and the dispersed model is another.
Every interaction in the centralised approach must go through this one large, powerful computer that houses the project. The developers engaged in the same project are represented by the boxes that resemble computers. While there is no central computer and every developer has a copy of the project in its entirety in the distributed approach, They can now work offline on a specific project feature in this instance as well.
Every developer has a complete copy of the project thanks to the distributed version control technology known as Git.
Here are a few significant words from the language of Git. As we discuss each one of them, keep coming back to these. You can now quickly scan them.
Source code manager (SCM) or version control system (VCS): A VCS enables you to, among other things, roll back changes made over time, see who most recently changed something that might be causing a problem, who first introduced an issue and when, and more.
Commit(Snapshot): Git views its data as a collection of copies of a small file system. Every time you commit, or save the current state of your project in Git, it essentially takes a snapshot of the state of all your files at that same instant and stores a reference to that snapshot.
Repository (Repo): A directory containing your project work as well as a few files that are often hidden on Mac OS X but are necessary for Git communication. Repositories may be present locally on your computer or remotely on a different machine.
Working Directory: Your computer's file system's visible files. The files in the Working Directory are what you work with when you open your project files in a code editor.
In contrast, the repository contains files that have been saved(in commits!)
The working directory used while using Git is also distinct from the idea of the current working directory used when using the command line, which is the directory that your shell is currently "looking at."
Checkout: The process of copying content from the repository to the Working Directory. There are numerous items that can be checked out from a repository, including files, commits, branches, etc.
Staging Area, Staging Index, or Index: A file in the Git directory that contains details about the content of your upcoming commit. A staging area is similar to a prep table where Git will place the subsequent commit. The staging Index contains files that are about to be added to the repository.
SHA: Each commit's SHA essentially serves as an ID number. It is a 40-character string that is made up of the letters and numbers 0 through 9, as well as the letters a through F, and is determined using the Git file or directory contents. The acronym "SHA" stands for "SHA hash". An SHA might appear as follows:
Branch: A branch is a fresh line of development that splits off from the main path of development. Without changing the primary course of development, an alternative line can go on.
The working directory, the staging index, and the repository—where all the commits are saved—can be thought of as the three primary areas of a git repository.
Let's say we now have three brand-new files in our working directory. JS, CSS, and HTML files. We must first add these files to the staging index in order to save their current states. We add them to the repository from the staging index, preserving the files' present state. Soon, we will see the orders to carry out that.
We now modify the CSS file once more, stage it, and add it to the repository.
We can see that the repository is keeping track of these modifications. Git thus takes a snapshot of the altered files with each commit and keeps it in the repository. Each commit is given a 7-digit commit ID, which corresponds to the first seven digits of the 40-digit SHA. A specific commit is identified by its commit id.
Creating a repository in Git
The three commands we'll be covering in this section are. Git clone, Git status, and Git init.
This command performs the following actions in the shell while in the working directory you want to track with Git:-
- It creates all the directories and files required for Git to track everything.
- These files are all kept in the. git directory.
- The "repo" that we have been referring to is located in the. git directory. This is where Git keeps track of everything and records all commits.
git clone URL
You must copy a project from the web when you need to work on one that is not already on your computer or when you wish to contribute to an open-source project. Now the project's URL may be easily obtained whether it is hosted on GitHub or Bitbucket. The repository is then fully replicated on your PC when you run the aforementioned command.
The folder's name is automatically the same as the one you cloned from. You can use the command to modify the name of the folder that Git generates.
git clone URL new-name
This command has now initialised the git repository in the project directory. We don't need to do "git init" once more.
To check the status of the repository we are in, run this command. Let's examine the results of running this command on the project that we previously cloned. Keep in mind that you must cd into that directory first.
I'll describe every line in the output.
- Git is on the master branch, as indicated by the statement "on branch master" (which is the default branch). In a subsequent section of this article, I shall discuss branches.
- A Git clone was used to copy this repository from another computer, therefore this is telling us that it is current with the one we cloned from. b) Your branch is up-to-date with 'origin/master
- No pending modifications that need to be committed to the local repository are indicated by the message "Nothing to commit, working directory clean."