What is Git?
Git is a free and open-source distributed version control system that allows you to track changes to files and coordinate work on those files among multiple people. It was created by Linus Torvalds in 2005 and has since become one of the most widely used version control systems in the world.
With git, you can keep track of your code history and have the confidence to do experiments with your projects and improve them without the fear of losing your work.
What is Github?
Github is a platform and a cloud based service which allows us to host our git repositories. Just like Git, it is distributed version control system that allows you to store data, track it and collaborate on software projects. Github also makes it easy to collaborate with others, as you can share changes and merge the changes made by different people into a single version of a file.
What is Version Control? How many types of version controls do we have?
Version control is the process of managing changes to files or documents over time. Version control systems are software tools that help you keep track of these changes, as well as collaborate with other people on the same project.
Version control systems have many benefits for software development, such as:
Backup: You can save multiple versions of your files in case you need to restore them later.
History: You can view the history of your files and see who made what changes and when.
Collaboration: You can work with other developers on the same project without overwriting each other’s work.
Quality: You can review and test your code before merging it with the main branch.
Deployment: You can deploy your code to different environments with ease.
Types of Version Control:
There are two main types of version control:
Centralized Version Control: A centralized version control system (CVCS) uses a central server to store all the versions of a project's files. In CVCS, a developer need to get a local copy of the source from the server, do the changes and commit those changes to a central source of a server. It is slower as every command needs to communicate with the server.
Distributed Version Control: A distributed version control system (DVCS) allows developers to "clone" an entire repository, including the entire version history of the project. In DVCS, every developer can have a local repository as well and have a complete history on it. Developers need to push the changes in the branch which will be pushed in the source repository. It is faster as every user deals with a local copy without hitting the server every time.
Why do we use distributed version control over centralized version control?
Offline Work: In DVCS you can copy an entire repository including history because of that you have a local copy of it in which you can do your work without the internet and later sync with the central repository once they are back online.
Faster Operations: It is faster as every user deals with a local copy without hitting the server every time. Even if the server is down workers can work in their local repository.
Full Repository Copy: Developers can "clone" an entire repository, including the entire version history of the project. This provides them with a backup of the project, and the security of code, and makes it easier to recover from data loss.
Branching and Merging: Branching is a core feature in DVCS, and it is much more efficient and user-friendly than in centralized systems. Developers can easily create branches to fix a bug and do their work without fear of losing it and then merge the changes back to the main branch when it's ready.
Some Basic Commands of Git.
Command Description
git init Initializes a new Git repository in the current directory.
git clone Creates a local copy of a remote repository.
git add Adds changes or new files to the staging area for the next commit.
git commit Records changes to the repository with a commit message.
git status Shows the status of the working directory and staging area.
git push Uploads local commits to a remote repository.
git pull Fetches and merges changes from a remote repository.
git branch Lists, creates, or deletes branches in the repository.
git checkout Switches to a different branch or restores files from a commit.
git merge Combines changes from one branch into another branch.
git log Displays a history of commits in the repository.
git remote Manages remote repositories linked to the local repository.
Create a new repository on GitHub and clone it to your local machine
step 1. Sign in to your GitHub account using your username and password.
step 2. Once you are signed in, click on the “+” icon in the top-right corner of the GitHub homepage. From the dropdown menu, select “New repository.” or, go to repositories and click on ‘new’ in the top right corner.
Step 3. Set up the repository: Now Add the repository name and other details like whether you want to keep it public(publically accessible) or private repo.
Then click on ‘create repository
you have successfully created a repository.
Clone Repo to the local machine
step1: click on <>code, after that, we can see a path, and copy that path
step 2: let's go into your local machine.
step 3: git clone <paste_the_copied_link_here>
it will clone your repository into your local.
git clone https://github.com/sutish/test.git
Git Log :
you can use this command to see the commit id and commit massage.
Push the changes back to the repository on GitHub.
git push origin <branch-name>
Thank you for reading!
Contact me at :
linkedin: https://www.linkedin.com/in/sutish-pradhan/
E-mail: psutish@gmail.com