Getting Started with Git and Github


Introduction: 

Git is a simple open source version control system. It stores the information of anything with different versions. Mostly, it is used to store the source code of any application. Other version control softwares include Subversion, Bitbucket. The main use of this version control system is to store different updates of the same project with different versions at the same place. It also helps when multiple people are working on the same project but on a different aspects associated to that project. This is just a command line tool.


Github is a git repository hosting service. It is a web based graphical interface that provides version control and source code management features of Git.


Workflow of Git:

Any local repository (any project stored locally) consists of three trees maintained by git. They are:

  1. Working Directory - This holds the actual files. 
  2. Index - This acts as a staging area. This is kind of storage space between the Working Directory and Head. This is a virtual space between Working Directory and Head.
  3. Head - This the place where information from Working directory is sent after committing the code. This is kind of a virtual space between working directory and Github.

Workflow from Git to Github:

Once the information in Git is committed to Head. It can be pushed to Github using a push command.

Creating a Git project and pushing it to Github:

1. Create a Git Repository

Create a new directory/new folder.

Perform git init in the terminal.  This place acts as working directory now


2.  Add files from Working directory to Index

This step is performed only when new files are created.

Any new files created in the Working directory should be added to the index with commands:


git add *  - to add all files to the index


git add <filename> - to add particular file to index


3.  Commit/copy the code to Head

Copying the code from working repository to Head is termed as commit.

Committing the code to Head is done with the command:


git commit -m "any committing message "


Note: Before performing the 4th step, there should be an existing remote repository in Github and a connectivity to the working repository in Git and remote repository in Github should be made. 

To create a remote repository in Github, Go to your Github account and click on create new repository and give it a name. 


Now, connectivity between the Git Working directory and Github remote repository is made with the command:

git remote add origin <server url for the project- either ssh or https >


This url is obtained in the Github account. Go to your Github account. Click on the repository that you just created. Click on the clone option on the right. It has the URL for that project.



4. Push/copy the code from Git to Github


Once the information in Git is committed to Head, it can be sent/pushed to Github.

Sending the code from Git to Github is termed as push.

To push the changes to remote repository in Github, here is the command:


git push


git push origin <branch name> - to push the changes to specific branch. master is the default branch


Comments

Popular posts from this blog

Getting started with Spring Boot Application and pushing it to Github

Spring Boot Caching

Performance test with Gatling