Git is a revision control and source code management software that is light weight, fast and free. if you are a developer, i would suggest learning it. Just using the basic functions of git is enough to help you code efficiently. It is also not necessary to put your code publicly in github.com. You can just use it locally or even create your own private git server. The truth is you can use it for anything and not just for source code. The first thing to do is download git at http://git-scm.com/downloads selecting your OS. After installation, we can now start using git.
1. Open your shell/terminal or powerShell in windows.
2. (Optional but i suggest you do it) Setup your global user and email setting by typing the following commands.
git config --global user.name "your name" git config --global user.email "email@example.com"
these information will be used everytime on your git commit or basically printing your name and email if you modify something inside the git directory.
3. The first thing to do is to go to the directory you want to manage.
4. Initialize git inside this directory by typing
5. You can now start adding files in this directory that you want to manage. This may confuse you at first but let me just say, any files you add or edit will not be tracked or saved in the git revision control history until you add it on the staging area. So every time you think that your changes or your new files are good to go to history, always use this command.
git add your_file
or use this to add all files in the current directory in the staging area
git add .
6. To check the status of your files if it will be included on your git commit ( taking a snapshot or history of your files ) use
git status will also give you recommendations on what to do with your files
7. Then, if you want to take a snapshot or version of the current tracked files use
git commit -m "message to remember your current change or snapshot"
if you don’t want to git add files every time, you can also use an optional switch -a to automatically add all new and modified files in the staging area and commit in one command. Use
git commit -a -m "message to remember your current change or snapshot"
8. Finally, use this command to see your history of changes in your tracked directory
the log history is very important for changing back your files from the current version to an old version in case you need it.
Git Basics 2
9. Removing or deleting files. You can delete your files manually but until you delete with this command, the files are still being tracked by Git.
git rm your_file
10. Renaming or moving files. In git, you can easily rename or move files to another file name using this command.
git mv your_file your_new_file_name
Important: you must remember that renaming manually without using this command means your old file is still tracked by git, and you still need to add the renamed file using the git add command. So this command is basically a combination of git rm and git add in one.
11. Then what if you want to go back in time and reset your files from any snapshot or version? Use
git reset --hard commit_sha_hash
Where to find your commit sha hash? use your git log command.
It is very important to take note that once you git reset, all your changes ahead of this version will be deleted and cannot be recovered.