Introduction
In this blog, we are going to see about the
Git
What is mean by Git?, Where it is used for and how it will be used will cover all the topics.Git
Git is a storage space (repository) where your project files and their complete history of changes are kept. It allows you to manage and track, and collaborate on the code at a time.
Types of Git Repository
- Local Repository
- Remote Repository
Local Repository
- It stores on your computer
- You can make changes, commit them and review your project history without needing any internet connection.
- EG : it is stored in .git file in your local computer
Remote Repository
It can be hosted on a server like GitHub, GitLab or Bitbucket.
It enables multiple developers to collaborate on the same project.
Supports operations like push, pull, fetch to synchronize changes with the local repository.
Initialization
Before you can start tracking your project files, it is mandatory to initialize the repository in your project folder.
git init
then add the files,
git add file_name
or git add .
-> Adding the current repository to the staging area.
Add specific files in the staging area.
git add--all
to add the files with the extension.txt in the current directory
git add *.txt
To add all text files with the .txt extension of the docs directory to the staging area.
git add docs/*.txt
to add a text files of a particular directory.
git add docs/
to add a particular directory to the staging area.
git add "*.txt"
Moving Stag area to commit area in a git repository
we have to give the commit command git commit
.
commiting process is done in the staging area on the files where added to the git add command.
git commit -m "Add existing file"
Cloning and Synchronizing with remote repositories
Git allow you to clone (create copy) the project files in your local machine , you can edit and make changes in the project files.
To sync with others, Git provides commands to synchronize local repositories with remote ones.
- Push
- Pull
Push
Push command is used to push all the commits of the current repository to the tracked remote repository. This can be push your repository to multiple repositories at once.
Pull
This command updates your local repository by fetching and merging challenges from the remote repository.
It ensures your copy stays synchronized when others have made updates
Additional Git Commands
Git Status
It is used to check the status of whether the files are committed or not in the GitHub repository
git status
Git Log
It is used to track all the changes made in the repository
If you want to hide any file while uploading online, then create a .gitignore
file and write all the files that you want to ignore.
Git Merge
It merges two repositories without losing data. It merges the specified repository into the current repository. `git merge `
Git Checkout
It is used to rollback to the previous version of the project which was committed earlier
Conclusion
Git is a major role player for creating and managing projects , we can clone, commit, update the project files and it can only be used the above commands.
See you on the next blog! Thank You
Top comments (0)