Git is a software that tracks changes in any initialised repository or directory. It's helps for coordinating with your fellow programmers to collaborate and for tracking changes in any set of files.
Git was created by Linus Torvalds in 2005 for development of the Linux kernel, and itβs now a fundamental developing tool thatβs used by almost all professional developers.
Git mainly help us in these two following terms :
- Collaboration
- Having A record of changes and previous state of code.
Many new developers and students have an confusion between Git and Github.
Let's understand how they are different :
Git is a version control system that keeps track and maintains a log of all the changes that are committed by the changer.
Whereas ,
Github ia a company that provide hosting services for the code and repository and let people collaborate which internally uses git for operation.
Git Installation
To get started with git and explore version control system we firstly have to install git locally in the system for that head over to Git Download and have a installation for your desired operating system.
The process is straight forward and with couple of next click and you are ready to head over to Git BASH.
The above picture shows the git bash screen which is the terminal which uses bash language for scripting. Before using some git commands and exploring the git features, let's first walk through some command cli commands which would help one getting use to terminal.
-
pwd command
: The shell commandpwd
displays the file path from the root directory to the current working directory.
-
mkdir Make Directory
: The shell command mkdir is used to make a new directory in the filesystem according to its argument. If a file path is given, the new directory will be placed at the end. Otherwise, it creates a new directory in the current working directory.
The Directory is added to home path to view the folder one can use GUI Application , but we are developers so π
-
ls List
: The shell command ls is used to list the contents of a directory. If no arguments are given, it will list the contents of the current working directory.
The above folder that We created is present in the folder can be found in the picture shown below :
-
cd Change Directory
: The shell command cd is used to move throughout the filesystem of a computer.
cd accepts a variety of arguments:
- Full file paths leading to some directory.
- Name of children Directory
- .. To move to parent directory of the file.
You can learn More of these basic cli commands here β‘οΈ Click me
Git Initialising
Before initialising lets check what version git is being installed in our system through this basic command :
$ git --version
To work with git we need some config for the user details as it manage the log associated with the changer maintaining the changes.
To set those we simply set git configs like username and email for the user. To do so follow these commands :
$ git config --global user.name "YOUR_USER_NAME"
$ git config --global user.email "YOUR_EMAIL"
After setting up you can check if they are configured well or not through these commands :
git -config --global user.name
git -config --global user.email
These would return your given values or string.
Now we are actually ready for the project so head over and create a folder and add any project you want to push over to github and keep a track of changes in git.
As we are done with creating a git repository , its time to add some files and commit the changes to log.π For this article am using a simple fronted site .
Now lets add these files to commit and then commit with a message "First dev commit" .
We can check all the logs for confirmation π
## Now lets Push this local repository to Github .
To push the code or your work to Github we first have to make a connection between the local repository and remote one for both fetching and pushing operation . For that lets first create a repository an blank one over github .
To establish the connection we would be needing the url : https://github.com/Abbhiishek/bookish-giggle.git
. These url can be found over your repository or else you just add .git in the last of your repository url from browser.
To make the connection we do :
git remote add origin url_here
Also to view the connection that are established we can use :
git remote -v
Now as the connection is established we would be pushing to github all the committed stuffs from local to remote repository .
To do so we do we have the command :
git push origin <branch_name>
We can see Github is updated with the pushed code
Hurray π₯³
Though this article was not intended to give you whole idea how to work with git , I tried my best to make things understandable. If Found helpful let me know in comment section.
In the next article would share how to push it to Github Pages or other services like vercel or netlify .π
kudos !
Top comments (0)