What is a GIT Repository? – GeeksforGeeks

Repositories in Git contain a collection of files from several different versions of a project. These files are imported from the repository to the user’s local server for later updates and modifications to the contents of the file. A VCS or version control system is used to create these versions and store them in a specific place called a repository. The process of copying content from an existing Git repository with the help of various Git tools is called cloning. After the cloning process is complete, the user gets the full repository on their local machine. Git assumes by default that the work to be done in the repository is as a user, once cloning is done. Users can also create a new repository or delete an existing one. To delete a repository, the easiest way is to simply delete the folder that contains the repository. Repositories can be divided into two types based on usage on a server.

These are:Bare repositories

  • : These repositories are used to share changes made by different developers. A user cannot modify this repository or create a new version for this repository based on the modifications made.
  • Non-bare repositories: Non-bare repositories are easy to use and therefore allow the user to create new file modifications and also create new versions for the repositories. The cloning process creates a non-bare repository by default if no parameters are specified during the clone operation.

repository1

Staging or workspace in a Git repository A

working tree in

a

Git repository is the collection of files that originate from a particular version of the repository. Helps track changes made by a specific user to a repository version. Whenever the user performs an operation, Git will search only for files that are present in the workspace, and not for all modified files. Only files that are present in the workspace are considered for the commit operation. The user of the worktree can change files by modifying existing files and deleting or creating files. There are some stages of

a file in the worktree of a repository:Untracked: At this stage, the Git repository cannot crawl the file, which means that the file is

  • never staged or committed. Crawled: When the Git repository
  • crawls a file, which means that the file is committed but not stored in the working directory.
  • Provisional: At this stage, the file is ready to be confirmed and placed in the staging area awaiting the next confirmation.
  • Modified/Dirty: When changes are made to the file, that is, the file is modified but the change has not yet been configured.

After changes are made to the

workspace, the user can update these changes in the GIT repository or revert the changes

.

Working with

a repository

A GIT repository allows you to perform various operations on it to create different versions of a project. These operations include adding files, creating new repositories, committing an action, deleting a repository, and so on. These modifications will result in the creation of different versions of a project.

Add

to a repository

After you make several modifications to a file in the workspace, GIT must follow two more steps to save these changes to the local repository. These steps are:

Add changes to the

  1. index(Staging area)
  2. Commit indexed changes to the repositoryAdd changes to

the index This process is done by using the git add command. When changes have been made to the tree/workspace. These changes must be added to the staging area to further modify the file. The git add command adds the file to the local repository. This organizes them for the confirmation process.

Syntax

:$ git add Filename

Different ways to use the add:

$ git add command.

To add a specific list of files to the staging area.

$ git add -all To add all files in the current directory to a staging area. $ git add *.txt To add all text files in the current directory to the staging area. $ git add docs/*.txt To add all text files from a particular directory (docs) to the staging area. $ git add docs/

To add all files in a particular directory (docs) to the

staging area.

$ git

add

“*.txt”

To add project-wide text files to the staging area. Committing changes from the index The commit process is performed in the staging area on files that are added to the index after running the git add command. This commit process is done by using the git commit command. This command commits the preconfigured changes to the local repository. syntax:

$ git commit -m “Add Existing File”

This commit command is used to add any of the crawled files to the staging area and confirm them by providing a message to remember.

staging process

Synchronizing with remote

repositories Git allows users to perform operations on repositories by cloning them to the local machine. This will result in the creation of several different copies of the project. These copies are stored on the local machine and therefore users will not be able to synchronize their changes with other developers. To overcome this issue, Git allows you to synchronize these local repositories with remote repositories. This synchronization can be done by using two commands in the Git. These commands are

:

  • push
  • pull

Push: This command is used to send all commits from the current repository to the crawled remote repository. This command can be used to push your repository to multiple repositories at once. syntax:

$ git push -u origin master

To push all the contents of our local repository that belong to the master branch to the server (global repository). throw: The pull command is used to retrieve commits from a remote repository and store them in remote branches. There may be a case where other users make changes to their copy of repositories and upload them to other remote repositories. But in that case, your copy of the repository will become obsolete. Therefore, to resynchronize their copy of the repository with the remote repository, the user only has to use the git pull command to get the contents of the remote repository. syntax:

$ git pull

Some more commands

:Git Status: Used to check the status of the git

repository, that is, whether the files are committed or not, files in the staging area or untracked file. $ git status Git

Log: Used to keep track of all changes made and by whom. Your command is

$git log.gitignore

: You can use . Gitignore if you want to hide any file when uploading it online. Just create a .gitignore file and type in all the file names you want to ignore.

Git Merge: Used to merge two repositories, without losing data. Merges the specified repository with the current repository.

$ git merge <repo-name>

Git Checkout: Used to revert to the previous version of the project that was committed at any previous time. You can copy the hash code from the git registry and use it to roll back. Let’s take a look at the code:

$ git checkout <hash-code>

Contact US