Monday, November 5, 2018

Git and GitHub for Version Control on Windows

Git is Version Control System also known as VCS that you install on your local machine and use it to check in, check out, commit your code just like any other VCS like TFS. However, in case of multiple developers working together can upload or merge their changes in centralized location called GitHub (also, can have in house Git Server).
Here is quick guide on using Git with GitHub.


Getting Git for Windows
image

  • Go through the installation process after downloading

image

  • By default Git Bash and GUI will be integrated with Windows Explorer, but can be disabled while installing.
image

  • You may keep default options during installation process, default options would work for most of users.

Setting up GitHub Account and Settings
  • Open https://github.com/ and create your account or Login if you already have account.
  • You have to add a project on GitHub where you would be creating repositories, each project can have multiple repositories and branches
image
  • Click on create repository to add and commit repository immediately.
Adding files to repository
  • You may directly add files and folders to GitHub using Web Portal GUI or by using CLI also known as Git Bash.
  • Git bash was installed as part of Git installation.
Adding files from Web Portal GUI
  • Adding files from Web Portal is very simple, you may simply Upload or Create New file.
  • Also, note that using Git Hub does not require you to install Git for Windows as it is completely web based.
  • You would get option to Upload or Create New file as soon as you go into Repository as shown below:
image

  • Once you select the file(s) as shown above, the file(s) should be committed
image
  • Add comments to commit and press Commit Changes to apply changes, this will complete the check in process using URL or Web Portal of GitHub.
Adding files using Git Bash

This process first requires you to create Clone of Repository from GitHub to local and then make your changes in local repository, once done then you can upload your changes to GitHub using Git Bash. Step by step process is given below.
  • Open Git Bash program. (Git Bash accepts linux like commands, for example: cd, pwd, ls, etc.)
      • If you would like to change current directory to C drive then command will be “cd /c”
      • Same way if you would like to see content of current directory then command is “ls”
      • To get current directory (aka Working Directory) path the command “pwd”
  • The first step requires to clone the repository from GitHub.
  • In this demonstration the directory used to keep clone is c:\github hence the command to change directory will be “cd /c/github”.
image
  • Also you would require git URL of your repository. You may get git URL from github repository page, by selecting option Clone or download as per screenshot below
image


  • Make sure that you are in working directory where you want to clone the Repository and execute git clone command “git clone [git URL]”
image

  • Git will use your current identity (Login name or ID) against changes and activities you would perform, you may want to change it to your preferred user name using config command.
  • If you add global switch to config command the changes will be applied to all repositories, otherwise changes will be applied to current repository only.
image
  • Global config below
image
  • Before you could make changes like adding files etc. you will have to checkout the repository. In previous steps you cloned the repository.
  • Command to checkout repository is “git checkout master” (master is main copy and you can create branches from master, for example development or test branch)
image
  • Now you can add files to the working directory or create new, once done add file(s) to repository “git add [filename]”
image
  • The next step is to commit changes in local repository using command “git commit –m “comments”
image
  • The final step in the process is to push the changes and the command is “git push”
image
  • To validate, you may go to Git Hub URL and you should see latest changes you made from Git Bash.
image












No comments:

Post a Comment

Using Azure Storage for SQL Backups

you may have taken backups on local storage, file servers, NAS, etc. Now a days it is becoming crucial you have backup copies available in...

Contact Me

Name

Email *

Message *