In this tutorial, I will describe how you can start using git in a Windows environment as your preferred version control system. I am assuming you have basic knowledge about version/revision control systems and may have used other version control systems already so that you know what commit/checkout/merge, etc., means.
What Is GIT:
In professional development, source control is an essential criterion to be fulfilled. Either you want to preserve the ability to resume back to an older stable code version of a project, or want to have the ability to work concurrently with other developers on same files with minimal overhead, you will need some kind of version control system implemented, for sure. There are many systems for this kind of task, like SVN, Perforce, Microsoft TFS, etc. GIT is a comparatively new addition to this list. But, it has become one of the most popular nowadays because of its benefits over others. Specially, the slogan fits very well with its criteria, which is ‘Fast Version Control System’. I am going to introduce a very basic idea for starting to work with the git version control system on a Windows environment.
Understanding Git For Other Version Control Users:
If you are already using Visual Studio with other version controls like SVN or Microsoft’s own team foundation server and have not used Git yet, you will have to think about Git a little differently. All of these version control systems are centralized, which means that after you do work, when you commit something, it goes directly to the central repository, usually hosted on a centralized/remote server.
Git Is DVCS:
Unlike other source control management systems I mentioned above, GIT is distributed. That means we can use it as a local repository and host it on a server. Each cloned git repository contains an entire revision history synchronized with others and can be treated as a complete repository at any time. So, if your server is destroyed, you won’t lose the revision tree for your repository, your local copy can be reinstalled on server and will act as the old repository exactly in the same way. You can create a new branch/merge with a revision without being connected to a central/remote repository as well.
Installing GIT On Windows:
You have to go to the official GitHub website. Then, you can download the Windows installer from the download section and install it. It’s that easy!
You will get two different versions to use: one is a command-line tool(known as ‘GIT Bash‘), and another is a GUI Tool(GIT GUI). However, the GUI tool’s functionality is very limited. So, it’s better not to use that and stick with the command-line tool. After a little practice, it will become easy for you.
Setting Basic Configuration:
Git recommends setting up your name and email globally so that it can use that info with your commits on the revision history. To do so, open the git bash tool and write the following two lines:
This is a one-time setup, as you did it ‘globally’. It will work for any git repository that you create in the future.
Create And Initialization Of A Repository On GIT:
To create and initialize a repository, first, you have to be in the directory you want to make as a repository. For this, you can re-use the ‘cd’ command line directive. Then, you have to run the initialization command. Additionally, you should configure your name/email on git global configuration for identification purposes. First, open the GIT Bash tool. Write command statements as follows:
$ cd F:/MyProjectFolder
$ git init
Remember, don’t try to use a Windows directory structure with a backslash(‘F:\MyDirectory’); that won’t work here. The ‘init’ command makes the directory a git repository and creates its necessary core files/directories(hidden).
If you want to retrieve a source from an existing repository(whether it’s locally or remotely), use this command instead:
This will get the latest version of the codes to the current git directory. In this case, you don’t need to use the ‘git init’ command.
Add Files To GIT Repository And Commit:
First, you will have to run the ‘add’ command for the file(s) you want to add to the repository. Then, we need to add a commit command. Here are code samples to add all files in the directory and commit them to git:
You Should use a comment for every commit. Remember, this commit will be made locally in your current git directory, nowhere else. If you have retrieved code from a remote repository and want to have your commit as part of that, use the following additional command after the above ones:
$ git push origin master
This will upload the local changes/commits to the original git repository. In short, ‘git push’ would also work if you aren’t using multiple origins. If you created a local repository first and now want to upload/publish it to a remote repository, you can use the command below:
$ git add origin url-to-repo
$ git push origin
Further Updates And Commit On GIT Repository:
It is also quite easy. After every update, you just have to run the ‘add’,’commit’, and ‘push'(if applicable) commands. The new commits will only take place for the changed files.
Further References:
There are a lot more command options for more advanced usage. I suggest you go through the Git online book to learn more. It’s free and very helpful. If you wish to host your project on a web server, you can use Github, which you can use either for a public open-source project(free of cost) or a private project(you have to pay a monthly fee). However, you can also use Assembly to get a free private repository for up to 3 users.
I hope this small git tutorial on the Windows environment will help you to some extent in starting this amazing version control system, which is now ruling the world of software development. Let me know if you have any comments/questions/suggestions. Happy coding 🙂
var JetpackInstantSearchOptions=JSON.parse(decodeURIComponent("%7B%22overlayOptions%22%3A%7B%22colorTheme%22%3A%22light%22%2C%22enableInfScroll%22%3Atrue%2C%22enableFilteringOpensOverlay%22%3Atrue%2C%22enablePostDate%22%3Atrue%2C%22enableSort%22%3Atrue%2C%22highlightColor%22%3A%22%23FFC%22%2C%22overlayTrigger%22%3A%22submit%22%2C%22resultFormat%22%3A%22expanded%22%2C%22showPoweredBy%22%3Atrue%2C%22defaultSort%22%3A%22relevance%22%2C%22excludedPostTypes%22%3A%5B%5D%7D%2C%22homeUrl%22%3A%22https%3A%5C%2F%5C%2Fcodesamplez.com%22%2C%22locale%22%3A%22en-US%22%2C%22postsPerPage%22%3A5%2C%22siteId%22%3A18994550%2C%22postTypes%22%3A%7B%22post%22%3A%7B%22singular_name%22%3A%22Post%22%2C%22name%22%3A%22Posts%22%7D%2C%22page%22%3A%7B%22singular_name%22%3A%22Page%22%2C%22name%22%3A%22Pages%22%7D%2C%22attachment%22%3A%7B%22singular_name%22%3A%22Media%22%2C%22name%22%3A%22Media%22%7D%7D%2C%22webpackPublicPath%22%3A%22https%3A%5C%2F%5C%2Fcodesamplez.com%5C%2Fwp-content%5C%2Fplugins%5C%2Fjetpack%5C%2Fjetpack_vendor%5C%2Fautomattic%5C%2Fjetpack-search%5C%2Fbuild%5C%2Finstant-search%5C%2F%22%2C%22isPhotonEnabled%22%3Afalse%2C%22isFreePlan%22%3Atrue%2C%22apiRoot%22%3A%22https%3A%5C%2F%5C%2Fcodesamplez.com%5C%2Fwp-json%5C%2F%22%2C%22apiNonce%22%3A%22155bc22a78%22%2C%22isPrivateSite%22%3Afalse%2C%22isWpcom%22%3Afalse%2C%22hasOverlayWidgets%22%3Afalse%2C%22widgets%22%3A%5B%5D%2C%22widgetsOutsideOverlay%22%3A%5B%5D%2C%22hasNonSearchWidgets%22%3Afalse%2C%22preventTrackingCookiesReset%22%3Afalse%7D"));
[…] I have discussed about very basics about git and github for git project hosting. However, none of those tutorials covered the important git […]