Table of contents
Vcs(Version Control System)
Version control is a system that records changes to a file or a set of files over time so that you can recall specific versions later. It allows you to revert the entire project to a previous state, compare changes over time, see who last modified something that might be causing a problem, who introduced an issue and when, and more.
Git
Git was originally authored by Linus Torvalds in 2005 for the development of the Linux kernel. Git is a Distributed Version Control System (DVCS). In this clients don't just check out the latest snapshot of the files-they fully mirror the repository. thus if any server dies, and these systems are collaborating via it, any of the client repositories can be copied back up to the server to restore it.
Installing Git
For Linux(for binary installer)
If you are on Fedora use the command - $ yum install git
If you are on a Debian-based distribution(like Ubuntu) use the below command -
$ apt-get install git
For Mac
Install the Xcode command line tool or homebrew (refer to git official page)
For Windows
Go to your browser and paste this link - git-scm.com/download/win
After opening that webpage you will see the direct link to download for Windows.
Setup Your Git
Install git for setting up your username and email address
Example -
$ git config --global user.name "John Doe"
$ git config --global user.email Johndoe.example.com
$ git config --global core.editor youreditor
Git has three states
Committed - It means that the data is safely in your local database.
Modified - It means that you have changed the file but have not committed it to your databases yet.
Staged - It means that you have marked a modified file in its current version to go into your next commit snapshot
Create to First local Repository
- There are two ways you can create your file:-
i) On your PC go to the file explorer and then top of the left side of the screen, you will see a plus(+) icon just click on it and create one folder.
ii) After that open that folder and again click on the (+) icon, select text document and name it as per your doc.(such as index.html, readme. md, style. css, etc.)
OR
i) Open your Internal terminal(such as PowerShell, git bash) in your PC and just type the below command to create a folder
mkdir Foldername // for both windows & bash
ii) After creating the folder type the cd mkdir Foldername command & click the enter button to change your directory to your folder and again type the below command to create your file.
type nul > filename.extension // for windows
touch filename.extension // for bash
iii) After that click the Enter button, hence you'll have your repository ready
- Initialize a repository that you created using the below command either in a terminal(bash) or in an integrated terminal in your(IDE) such as Vscode.
$ git init
- Now you have your local git repository.
Git Basics Command
Some important git commands are explained below -
git add .
- this command helps to track a new file in your projectgit commit
- this command helps to commit after staging a filegit status
-this command helps to check which files are in which stategit diff
- this command helps to see the changes in the files.git log
- this command helps to see the history of the commits.git branch <branch name>
- this command helps to create a new branch.git branch
- this command helps to show a simple listing of your current branches.git checkout <branch name>
- this command helps to switch to an existing branch.git merge <branch name>
- this command helps to merge the branch to the main branch in your repository.git remote add origin <remote repository URL>
- this command helps to add a remote repository to a local repository.git pull [remote-name]
- this command helps to get the data from your remote repository.git push -u origin main
- this command helps to upstream the remote branch for the local branch.git push
- It helps to push code to a remote branch or on the server
Git has many useful commands that will improve your productivity, below I have attached the link to download the free Git cheat sheet which I created while learning Git.
Github
GitHub is the single largest host for git repositories and is the central point of all collaboration for millions of developers and projects. a large number of all git repositories are hosted on GitHub, and many open-source projects use it for git hosting, issue tracking, code review, and many other things.
Setup Your GitHub Account
Go to github.com and click on the sign-up button then, set up your free account by providing a username, your email and a password, and click on the sign up for GitHub button, after verifying your email which GitHub sends you to your email.
Working With Github
After setting up your GitHub account, let's see how to make a copy of any public(open-source project) repository on Git Hub.
Go to Git Hub and find any repository that is familiar with your skills & hit click on that repository.
See the fork option on the above right-hand side of the repo, click on that option.
After clicking the fork button(Github makes a copy of the project that is entirely yours),you'll redirected to another window and on that window click on the Create Fork button
Right now, you have your remote repository not a local repository on your Computer or PC. To create that you have to clone it.
For cloning that repo, check below METHOD 3
The given methods will help you connect remote repos to local or vice-versa
- To add a local repository to remote (METHOD 1)
Create a new repo on GitHub and copy the clone https code
$ git branch -M main
(on local repo)$ git remote add origin
https://github.com/XYZ$ git remote
$ git remote -v
$ git push -u origin
- To add a local repository to remote (METHOD 2)
Navigate to the project directory using the terminal (or command prompt).
Initialize a new Git repository using the command
git init
.Add all the files to the staging area using
git add .
(note the period after "add").Commit the changes using
git commit -m "commit message"
.Create a new repository on GitHub.
Copy the URL of the remote repository.
Add the remote repository using the command
git remote add origin <remote repository URL>
.Push the changes to GitHub using
git push -u origin main
.
How to clone a repository from GitHub(METHOD 3)
Go to the GitHub website (github.com) and navigate to the repository you want to clone.
On the repository's main page, click on the "Code" button. It will open a dropdown with options to clone the repository using HTTPS, SSH, or GitHub CLI. Choose the method you prefer.
If you choose HTTPS, click on the clipboard icon to copy the URL to your clipboard.
If you choose SSH, click the "Use SSH" button, and a similar clipboard icon will appear to copy the SSH URL.
Open a terminal or command prompt on your local machine.
Navigate to the directory where you want to clone the repository. You can use the
cd
command to change directories.Once you are in the desired directory, use the
git clone
command followed by the URL you copied earlier. git clone https://github.com/username/repository.gitPress Enter to execute the command. Git will connect to the GitHub repository and download the files to your local machine. The repository will be cloned into a new directory with the same name as the repository.
Once the cloning process is complete, you will have a local copy of the repository on your machine.
Contribute to a public repository on GitHub
Follow the below steps to contribute to open-source projects
Clone the forked repo of the project locally.
Create a descriptive topic branch.
Make changes to the code.
Check that the change is good.
Commit the change to the topic branch
Push that new topic branch to commit back up to the forked project
Open a pull request on GitHub.
After that, the project owner either merges your code or closes your pull request. after discussing it with you.
Conclusion:-
Hence, Git is a version control system that records changes to a file or set of files over time. It allows users to revert the entire project to a previous state, compare changes over time, and more. Git is a Distributed Version Control System (DVCS) that fully mirrors the repository. on the other hand, GitHub is the largest host for git repositories and a central point of collaboration for millions of developers and open-source projects.
Follow Me On Socials :
Like👍|Share📲|Comment💭