Git is a Distributed version control system. If you are programming you should know about and be using version control. Here are 4 easy steps to getting started with Git as your version control.
Now there are two assumptions going into this. The first that you have downloaded and installed Git. The second is that you can navigate to your source from a command line.
Step 1 – Create the Repository
So this is where the prerequisites come in. Using Git Bash, that you have already installed, go to the directory that you have your code in. Tell Git to create a new repository, right where your code is.
user@computer /c/path/to/your/code/ $ git init
You should now see a message telling you that it has created an empty repository in a folder called “.git” in your directory.
Step 2 – Add Your Files
You need to add files that you want into the repository. You do this with the add command. When using add you can supply a filter like “*.cs” or “*.css”. In this example we want to add everything.
user@computer /c/path/to/your/code/ (master) $ git add *
Step 3 – Verify Your Staged Files (Optional)
With most things in software development it’s not a bad thing to be a little paranoid. However for the reckless, this step is optional. Verify that the files you want are set to be added to the repository.
user@computer /c/path/to/your/code/ (master) $ git status
Step 4 – Check in Your Files
Now that you have all your files staged and ready, check them in to the repository.
user@computer /c/path/to/your/code/ (master) $ git commit -m "Your comment goes here"
That’s it. Your done! In the future when you want to add the changes you have made or new files use the add command again. That’s something different about git. You use the add command for changes and new files. Then when you are satisfied with the staged changes call commit again.
That’s the pattern when developing with Git:
- Make updates.
- Stage the changes.
- Commit the changes.
You can even combine step two and three with the -a flag. However, then you couldn’t verify your staged files before the commit…
user@computer /c/path/to/your/code/ (master) $ git commit -a -m "Your comment goes here"