Basic GIT commands for beginners

Basic GIT commands for beginners

Using GIT to do versioning on your code or sharing work with your colleagues might sound scary. You have to understand how and where your code goes and you have to do it via command line… Just scary.

If you are on Windows you will need to install GIT tools – most likely GIT-SCM. Then you will probably need an account with Github or Bitbucket or access to your internal GIT server – this is where your code will be saved.

Here are the most important git commands

  • git init – initialize a new git project. Can be applied on an empty folder when starting a new project or on existing code
  • git add -A – adding the files to a queue of the repository (this is a bit tricky to understand because the files are already there, but adding a file to the repository is actually about letting know GIT that there are some files there)
  • git commit -m “version name” – this actually adds the files from the queue to the log (so it’s actually making a record of the current status of the files, if you modify them afterwards you can always reverse to the version of the commit). So far the repository is only on your machine
  • git remote add origin URL – lets the local GIT repository know there is a remote place to save the commits (usually bitbuket or github)
  • git push origin master – publishes the commit version to the remote repository (and therefore is also a form of backup as the code is now copied to an external server)