Walk through with GitHub in 5 mins

sourabh sahu
6 min readOct 21, 2019

Many a times you must have faced a situation when you lost the content or code while trying to improve it or you are working in a project in collaboration with your team mates using shared directories.Its painful when somebody changes the file you are working on it.You carry your copies of code and your friends copy and spending lot of time in merging and fixing the bugs raised due to merging.Above mentioned problem are very common with programmers before version control systems. Now a days almost every IT company uses some form of version control systems.

Various version control and collaboration tools are available some are propriety and few are open sourced.One of the famous among tech community is GitHub.

Version Control Benefits

  1. Backup and Restoration: Using Github, one can perform backup of the files and restoration of previous files.
  2. Synchronization: Developers works in synchronized mode and easily collaborate.
  3. Undo Operation: Users can perform undo to previous versions, even they can recover code which was written long ago.
  4. Change Tracking: Users can track various changes performed on a file, who has changed the file, when was the file changed.Its important feature for product managers to identify the cause of crash and escalate accordingly.
  5. Freedom to work locally: Its like a sandboxes that user can create and work on it.
  6. Branching and Merging: Its one of cool features which allows users to work in collaboration. Files are stored in a special directories called as repositories.If others want to work in collaboration or want to work on special features.Branches are created from repositories and users can work on those branches.Branches will not be a part of original repositories and changes in files will not be reflected in original repositories directly.

VCS, systems can be setup locally in your environment or you can use existing servers available for use, If you are small company or group of people who do not want your code or files to be stored on other servers, you can setup local servers using open source version control systems.

Various version control software: Git, SVN, VCS, Mercurial.

Version Control Clients: If you just want to use GitHub or SVN for code repositories, you can install client software and start using github. Github client comes as CLI (Command line Interface) & GUI. You can download github client from https://git-scm.com/downloads as per your system configuration. This will install both git bash(CLI) and git GUI.

GIT Terms

  1. Repository (Repo): Directory where your files are stored.
  2. Server: Computer storing the repositories.
  3. Working Copy/Working Area: it is the local computer directory in which you are working or making changes.
  4. Trunk/Main: Its the original repository, where we keep the main production ready content.
  5. Staging Area: Its the virtual directory where you add the contents after you make changes in files/directories.

Lets get started using GITHUB.

  1. Creating or Cloning a Repository: You can create a new repository or you can clone the existing repository.

Create a new folder or go inside the existing folder which you want to move to repository.

git init

Now you can add new files or update files as per your requirements.Now you can see the status of your repository using git status command.I have create a new text file abc.txt inside the mydemorepo

git status

Now you have to add the files to your staging area. The git works on the concept of Working directory. The files in red color shows the files are not added to staging area. You can add the files using git add command, here you have to specify the file name or you can use . for all files available in current directory.

git add .

You need to perform commit operations to move your files from staged area to working directory.For that we have to use git commit -m “message”. Here message is important part through which you identify what changes you have performed in files.

git commit -m “your custom message”

Now you have to move your files from local repository to remote repository on github. For that we have to create a repository on github

You have to provide repo name and create a new repository.Copy the url i.e. http://github.com/yourusername/reponame.git

Add your remote url to your local repository using.

git remote add origin url

Now you have to push your local repository content to the remote origin repository. Following command will move the content and you can see in the code section of github repository.

git push -u origin master

Cloning the existing repository: You can clone the existing open source repository using url of the git repository.

git clone url

Similar you can commands like push for adding files back to your repository.

Log: You can view the logs using git log command this will show you the details of previous commits along with revision id.

git log

Revert: you can revert to previous versions using git revert command

git revert commit_id

Branch: In large projects, you need to create branches so that other users can work and commit in their local branch rather than on main trunk it eliminate possibility of crashes in main repository.

git checkout -b “name of the branch”

Now you can add your branch to remote branch using

git remote add “name of your branch ” “name of other branch where you want to add”

Now you push the local branch to remote location using git push — set-upstream origin “your new branch”

Now you can view the branches in github.com under your repositories.

Merge: You can merge the changes made in your branch with master using following commands.first you need to be inside master branch using git checkout master command and then you have to perform merge operation using git merge “name of your new branch”

git checkout master

git merge “name of your new branch”

At the time of merging you may get into conflict status because of the changes in same by different person.Now your have resolve the conflicts by looking at the conflict line.

Click here to check my presentation on github

--

--