What is GIT?

Amasha Shalindi De Silva
3 min readJan 27, 2022
Photo by Yancy Min on Unsplash

GIT is a free and open source version control tool which we use to manage our projects efficiently. Let’s talk about how you can use Git both inside Visual Studio Code and on the command line to do things such as version control, how to clone repositories, how to fork make pull requests and merge repositories and so many exciting things.

How to push your code in to Git hub

I’m using a small example to explain the concept. First you have to open your Command prompt and navigate to your home directory using cd command. We can make a directory to contain your repositories using md command. Now you can navigate in to your directory using cd. Then you can create text file using type > nul <filename>in windows environment. Mac users can create a file using touch command.

Then you have to simply edit the text file.

$ ls

Mac users can list the contents of your repos directory using the ls

The git init command creates a new Git repository. The git add command moves changes from the working directory to the Git staging area. We can track the changes by using git status command. The files which are in staging area shows in red color. The staging area is similar to a rough draft space, where you can git add the version of a file or multiple files that you want to save in your next commit. We use git commit command with a message. The git commit -m ‘message’ captures a snapshot of the project’s currently staged changes. The git log command shows a list of all the commits made to a repository.

Now you have sign into your git hub account account and create a repository as shown in the below image.

Now you have to copy the repository link as shown below.

To add a new remote, use the git remote add origin <repository link>command on the terminal, in the directory your repository is stored at. You are ready to push your first commit to the remote repository. The git push -u origin master is for pushing your changes which requires a branch to push to call it origin and then specify the branch name.

The git diff command displays the differences between files in two commits or between a commit and your current repository. The git checkout command helps you to navigate between the branches created by git branch .

The below diagram summarizes all the concepts which we have discussed.

Photo by Sebastian Dubois

Conclusion

Here we talked about how to simply push your code in to Git Hub. In the next article I will talk about how to get a remote repository in to your working directory and how to work with it by creating branches and how we use version control.

See you in the next article!! Stay tuned!

--

--

Amasha Shalindi De Silva

Undergraduate at University of Moratuwa, Faculty of Information Technology