Git command screenshot


I think that one of the bases for a good software development is the use of version control tools. In my case Git, but you could also use other tools such as Subversion.

Have you lost or accidentally deleted a file? Do you want to undo some changes? Difficult management when working multiple programmers? Git can help to solve these problems.

It will take time to have a good control of Git, but it is worth the effort if you want to improve your development skills. In this first post, I will explain some basic commands (UNIX) to initialize a local repository:

  • Move to the root of the project:

  • cd /path/to/my/project

  • Add a plain text file with the name ".gitignore" (note the dot). This file is used to indicate which files should not have control, that is, which files should ignore. Simply add for each new line the name of the file to ignore, with absolute path from the root of the project. Example to initialize the file:

  • vim .gitignore

  • Initialize an empty repository, that is, initialize the location where digital information is stored:

  • git init

  • Add files that should start having tracking:

  • git add filename

    If you want to add all files that are not ignored, you can use:

    git add --all

  • Confirm the files that have to be followed, with a confirmation message (use a descriptive message to understand that has been modified or status of files):

  • git commit -m "Initial commit"

With this, it has been defined a local repository to keep track of different versions of the project. And now, what I can do?

Some of the most basic actions are:

  • To know the status of the project, that is, compare from the last commit and, for example, display the files that have changed:

    git status

  • To show exactly the differences occurred in the file:

    git diff filename

  • Discards the current changes to the file, to return to the status of the last commit:

    git checkout filename

  • To make a new commit and save the data in the local repository:

    git add filename

    git commit -m "Second commit"

  • To show the list of commits that was made:

    git log

This first entry is an introduction to making a local repository for a single developer. In future entries, will be introduced adding a remote repository, creating different branches, moving between different commits and multiple developers to working simultaneously.

I hope you liked the post, if you find any errors or have any questions, do not doubt to contact on our Twitter account @tocappcom

About Author

I'm passionate about simply, casual, minimal and experimentals games.