Using Git to Manage Changes in Code Without Trashing It

Version control is a good idea in order to keep track of changes in your code — especially when working with multiple files in multiple directories.

“Git is a free and open source distributed code management and version control system that is distributed under the GNU General Public License version 2. In addition to software version control, Git is used for other applications including configuration management and content management.”
http://searchitoperations.techtarget.com/definition/Git

One of the best used version control systems is Git created by Linus Torvalds who created Linux.

You can install Git in various operating systems including non-Unix systems like Windows (Git Bash).

First we have to introduce yourself to Git.

  1. Initialize Git.
    git init
  2. Then introduce yourself to Git. This is the way you can commit transactions.
    git config --global user.name "[your_name]"
    git config --global user.email "[your_email]"
  3. You can use helpful colorization of commands in Git.
    git config --global color.ui auto
  4. Of course, we can edit our configuration file (.gitconfig). Note that files starting with a period ('.') are hidden.
    [editor] .gitconfig
  5. At this point, you can tell Git what files it has to watch.
    git add [directories/files]
  6. Of course, if you prefer to add all the files in a sub-directory, you can add of it.
    git add .
  7. To make sure that Git is running, you can ask for its status.
    git status

Once Git is running and collecting changes, we can manipulate the changes.

  1. We can ask Git what changes have been done in our code.
    git diff
  2. We can also ask what changes have been made in each file.
    git diff --staged
  3. Once we accept the changes, we can COMMIT them.
    git commit -m "[message/memorandum]"
  4. We can group these changes before committing creating branches — alternate copies of the project in order not to destroy the original code.
    git branch [branch_name]
  5. Once changes are approved in the branch, we can merge the changes into the new BRANCH.
    git merge
  6. We can then upload the new branch into the original.
    git push

For more information, get the GitHub Git Cheat Sheet (local copy, owned by GitHub) or go to try.github.io.

I would like to thank Julia López (@yukideluxe) from Spain and Kimberley Cook (@KimberleyCook91) from England for helping me put this quick tutorial together.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.