-1

I went for an interview where they asked me whether I use GIT-REPOSITORIES to merge my projects. For which I was quite. I looked Wikipedia and Other stuff on net for this but didn't find anything that can force me to go for it. Please tell me what exactly is GIT-REPOSITORIES and how is it useful. Is it beneficial for me as I am totally confused by all that stuff on the internet ?

Currently, I create projects in PHP by dividing them into smaller independent modules and then merge them all by myself.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Jiteen
  • 429
  • 2
  • 6
  • 23
  • Is your question about Git, a specific command in Git, or about repositories? – nils May 02 '14 at 08:51
  • 2
    What they meant was, if you use Github for version control? – user2798227 May 02 '14 at 08:52
  • 3
    Maybe here is a misconception about what git is. It is a source code management system like svn or mercurial. – wumpz May 02 '14 at 08:56
  • 1
    @wumpz Yes the OP is clearly brand new to the idea of version control and GIT is just the example he was asked about. I've explained a scenario which should hopefully make the penny drop for someone brand new to the idea of source control. Although I don't know why it was downvoted. – i-CONICA May 02 '14 at 09:12

2 Answers2

2

Git is just one of several types of source control software.

At my day job, we use Mercurial, which is a DVCS (Distributed version control system).

Imagine you're working on a website and you've got a remote server. I guess right now you're downloading files via FTP, editing them, and uploading them. Do you take backups incase it goes wrong? What if you mix up backups, or you're not sure which change made the error? Then I guess you've got to manually re-upload each of these files into the right places, which will likely break the website for a period of time as files are out of sync.

Also imagine you're working on a codebase that's also being worked on by colleagues. Dave tells you he's just finished all that work on db-abstract.php, but then you get a sinking feeling, as you've just changed a load of code in db-abstract.php too.

With source control, when you make changes to files, you commit the changes, and the changes you've made are all recorded. It's recorded what lines of code you've added, and what you've removed.

When you've finished your work you can "push" them to a central repository where others can "pull" your changes. If you and Dave realise you've worked on the same file, you'll get a merge conflict. You'll then be shown a two sided screen where the changes Dave made, and the changes you made are compared. It'll try to merge them automatically, but if it can't, it'll ask for your help. You can then clearly see which bits of code have been added, changed and why. You'll merge the files together, then commit that change.

Eventually you end up with a whole load of changes that add a brand new feature to a system across possibly hundreds of files, these will all be grouped together into a branch, which describes the feature. All you have to do to make those changes live is push them to the live server, and on the live server, update it's working directory to this branch, or merge the branch into it's default branch. All the changes will instantly be live. If anything went wrong on the live server, or from user testing, you can simply "rollback" which will instantly revert all those changed files to their previous versions.

Once you've worked with source control you'll never go back and you simply cannot work on large code bases collaboratively with other devs without it.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
i-CONICA
  • 2,361
  • 9
  • 30
  • 45
  • I really appreciate your point. I am actually a newbie for this Git stuff. Now as I have an Idea about what it actually do, I would definitely like to implement it (at least once) in my project. – Jiteen May 02 '14 at 09:15
  • I'll be glad if you can share any Tutorial Link that can help me from a 'Beginner' perspective. Thanks! – Jiteen May 02 '14 at 09:16
  • I'd recommend Mercurial. There's a good beginners guide to it here: http://stackoverflow.com/questions/1170338/mercurial-for-beginners-the-definitive-practical-guide But basically, install mercurial, then either use it via command line or install TortoiseHG, which is an interface to Mercurial. Then go to your project folder and run "hg init" or click "add repository here". Your project will then be a repository and from then on, any changes you make will be tracked. Once you've seen the magic, you'll be dancing around the room. :) – i-CONICA May 02 '14 at 09:31
  • Thank You very much. I'll surely follow your words. Thanks a ton! – Jiteen May 02 '14 at 09:45
  • Also, if you use an IDE based on Eclipse, (Eclipse, Zend Studio, Aptana, etc) you can use the MercurialHG plugin to integrate the commit, pull, merge, push, branch, etc functionality right into the IDE. (I'm sure other source control and other IDEs have similar functionality too) – i-CONICA May 02 '14 at 13:10
-1

If you work alone, you shouldn't bother with git. Git in general is a version control system which allows you to "jump" back to any point of development. Also its extremely useful if you work in a team - everyone has his own "branch" where he develops new functions, designs or something else, and later you can merge every branch into the "master" branch.

Git has a lot of functions which i cant cover here - because i dont even know all myself.^^ More infos can be retrieved on the official page:

http://git-scm.com/

Realitätsverlust
  • 3,941
  • 2
  • 22
  • 46
  • 4
    If you work alone or not, source control is invaluable for tracking changes and changesets in projects. Are you copy/pasting files and naming them file.ext-backup? The first sentence of your answer is awful advice. – i-CONICA May 02 '14 at 09:03
  • 1
    I work almost exclusively alone, and I would never, ever consider going back to the dark ages of working without version control. This is very bad advice. – ChrisGPT was on strike May 02 '14 at 12:07