Git part 2 - basics

Hi!

Some times did not come here any new post, thus time to change it. Soon you will learn about how to start work with git, how effectively use this tool and how to join to exist project. Today next post from git series.

If you start your own project or you want join to existing, you have to make some place to work. With git it takes... a while. Just initilize repository in prepared directory using

git init

Now you initlized your project in git. It's good to personalized it. I think about exclude some not needed in repository files. We make divided for two cateogries of files: global files, which every programmer will have, e.g. directory with uploaded images and individual files like temporary files of your IDE. In first case we excluded files by add path to file in .gitignore. Modification of this file will be commit to repository. We can tell this is global file.

In case of privates files excluded should be in .git/info/exclude. This is local file and will not be send to repository.

OK, if excluded configuration is done time to next step.

If created repository initializing some project you can do nothing special. If you finished some part of project and you will want send files to repository just make

git add .
git ci -m 'Short commit description'
git push anchor-to-repo branch

Of course you can add concrete files replacing dot by file name.

If you continue existing project you can clone it

git clone anchor-to-repo

Of course you have to permission to clone repository. If it is on your account - problem doesn't exist. If it exist on someone else account you have to fork it firstly. Next you can clone using your fork. Like you noticed we are using addresses to repository very often. It could be hard to remember these. It's worth added shourtcut to addresses.

git remote add shortcut-name anchor-to-repo

You can check added shortcuts using

git remote -v

Usually assumed that main repository shortcut name is origin.

OK, everything good, you make some part of your project. You would like to check which files changed/added/removed. To check it you can use command

git status

List of display files will have two colors, green for files which will be commit in the next possibility and red for unstaged files. If you want staged files use command which know well

git add .

If you can unstaged file use display in status prompt

git reset HEAD file_name

If you want make fast review of changes you can diff these by

git diff

In diff and status command you can user --staged property and show only these file which will be commit.

By the way. Short version of commit command you know. If you can use all capabillities use

git commit

Now will be display file. You can add there short description of commit and next to empty row additional description.

To remove files, instead of standard rm use

git rm file_name

It let you remove files form direcotry and repository.