DEV Community

Cover image for Getting Started with 'Git'
BHAVIN VIRANI
BHAVIN VIRANI

Posted on

Getting Started with 'Git'

In this Blog i'll cover some basic commands of git, using that command you can easily work with git and Github as beginner.

  • Before starting this this blog I want to mention that Git and Github are not same. many people are understandably confused😕 between this two words at their beginning.

GitHub is a website for hosting projects that use git for version control.


What is git ?

  • Git is a version control system (VCS) that makes easier to track changes to files(code). For example, when you edit a file, git can help you to determine exactly what changed in your file, who changed that file, and why change that.
  • Git is a command line tool. it is very useful when we are working on team project or multiple people working on same project

What is github ?

  • GitHub is a Git repository hosting service, but it adds many of its own features. GitHub provides a Web-based graphical interface. It also provides access control and several collaboration features
  • Git also helps us to store our code safe and secure🔐 and many people use git and github daily to track their daily work. It makes them different from others.

Installation

  • To use git we'll need to download and install git on our system by using git. There are both options are available in market. command-line interface(CLI) and graphical user interface(GUI) as Github desktop but I recommend CLI for beginners.

  • After installation to check if git was installed properly or not execute the command:

git --version
Enter fullscreen mode Exit fullscreen mode

First step after Installing Git

  • The first thing you should do when you install Git is to set your user-name and email address. This is important because every Git commit uses this information
  • you can set your user-name and email using this commands and also change them at any time
git config --global user.name "<User-Name>"
git config --global user.email <Email>
Enter fullscreen mode Exit fullscreen mode

Create local git repository

  • We'll require git repository to use functionalities of git by using given command.
git init
Enter fullscreen mode Exit fullscreen mode
  • This'll create hidden .git folder in current directory. this is the "repository"(or repo) where git stores all of its internal tracking data. Any changes you make to any files within the original folder will now be possible to track.
  • The original directory is now referred as working directory.

Staging

The staging area (aka index) is a container where git collects all changes which will be part of the next commit.

  • use below showen comannd to add individual files into staging area git add <File1 path> <File2 path>...
git add README.md app/*.txt
Enter fullscreen mode Exit fullscreen mode

we also stage all changes together

git add -A
OR
git add .
Enter fullscreen mode Exit fullscreen mode

status

git staus

  • Above command is very useful. It gives overall status of working git directory
  • The git status command displays the state of the working directory and the staging area. It lets you see which changes have been staged, which haven't, and which files aren't being tracked by Git.

Commit

The "commit" command is used to save your changes to the local repository. we also need commit message it is important to help other people understand what was changed and why you changed it.

git commit -m " <Commit message> "
Enter fullscreen mode Exit fullscreen mode

push

The git push command is used to upload local repository content to a remote repository.

  • But there is one problem. we can't push directly our local repository to remote repo. in Order to do that first we need create repository on githuib and configure that remote repository with local repository. let's see how
  • git remote add <remote_name> <remote_repo_url>
git remote add origin https://github.com/bhavinvirani/my_repo.git
Enter fullscreen mode Exit fullscreen mode

after creatig a repository on the GitHub, You will find the link on that repository itself

Now, we can push our data on remote repository using this command

  • git push <remote_name> <remote_branch_name>
git push -u origin master
Enter fullscreen mode Exit fullscreen mode
  • If you are pushinga local branch for the first time on a remote, the "-u" option is helpful. It makes sure that a tracking connection between the local and your remote branch.
git push
Enter fullscreen mode Exit fullscreen mode
  • After having set tracking connection, you can perform future pushes without providing additional options - since the tracking connection provides default values for the push command.

Here i Show whole flow of git commands

git init
// make same changes in working directory
git add -A
git commit -m "made some changes in working directory"
git remote add origin https://github.com/bhavinvirani/my_repo.git
git push origin master
Enter fullscreen mode Exit fullscreen mode

Conclusion

In this blog we learned basic command of git and how to push our local repository to remote repository, It is good to use git and github daily to track our code or data.

Stay tuned for some advanced git commands and topics like branches and operations with remote repository which I cover in next article of this series


checkout my Github 👁

Typing SVG

IT engineer, I like to Learn and Build.

  • 🌱 Always learning
  • 🤝   I’m looking forward to collaborate with other developers and learn from them.
  • 📪 How to reach me: bhavinvirani45@gmail.com

Connect with me:

[/in/bhavin-virani-2a14441b7/](https://www.linkedin.com/in/bhavin-virani-2a14441b7/) [BhavinVirani45](twitter.com/BhavinVirani45) [/bhavinvirani](https://dev.to/bhavinvirani)


Languages and Tools

javascript javascript mongodb python git mysql linux


✨  GitHub Stats  ✨

bhavinvirani

 bhavinvirani

bhavinvirani

bhavinvirani







Top comments (2)

Collapse
 
rohitk570 profile image
ROHIT KUMAR

great

Collapse
 
bhavinvirani profile image
BHAVIN VIRANI

Thank you 😊