0

I'm teaching myself Github and have trouble understanding the overall way it is to be used. I'm not sure if my work flow is correct. My understanding a project corresponds to a repo, so I have one for sorting algorithms. I had implemented a quicksort algorithm. Yesterday I began implementing an introsort, but I made a minnor change to a comment in the quicksort.

I then did the following

  1. git add .
  2. git commit -m "Began creating introsort implementation"
  3. git push origin master

However, since a minor chagne was made to the quicksort source, now in Github quicksort has the message "Began creating introsort implementation" which kind of isn't the right place for it.

Is this a problem? What did I do wrong? I guess I shouldn't have used git add . and instead did the introsort source by itself. Someone was telling me that a new branch should be made while working on different parts of the same project. Is this right e.g. a new branch for each module? And then they can be merged together when they're working? So using Git branches out at first and then unbranches?

Celeritas
  • 14,489
  • 36
  • 113
  • 194

1 Answers1

1

You make a new branch before you start work on a new functionality. You commit your work to that branch. Once your new functionality works, you make a pull request so others can review changes and merge it into the target branch.

Your workflow is correct, if you work solo, but, if not, you should add git pull just before pushing.

Jekabz
  • 41
  • 3
  • When starting a new project, which do you do first: create the local project using the IDE, or create the repo first (and initialize it with the README file) and clone it? – Celeritas Apr 04 '16 at 10:21
  • I usually create the repo and then just clone it locally - this is simplest. If you have some files already, just go ahead and make a new local repo by `git init`, then do `git remote add` for remote repo. If you already have project from IDE, I advise you to make .gitignore file, to ignore IDE specific project files and compiled files. Note that git will not allow you to commit an empty folder. – Jekabz Apr 04 '16 at 11:52
  • Thanks. So how exactly do you do the first scenario, with an IDE like Netbeans? For example you create a repo on Github, then clone it. But obviously there's no source code yet as you just made it. So what option do you choose in the IDE, I would think use source code from existing project but there isn't any yet? In the past I've tried just making new source code but this causes a merge conflict. – Celeritas Apr 04 '16 at 20:38
  • Well I dont really understand what are you trying to achieve. Also, I have never used any IDE for managing my git repos, but it must be possible. I usually just use git from command line. You can only get merge conflicts when there are changes in one and the same file on two branches, that are being merged. – Jekabz Apr 04 '16 at 20:48