Search code examples
gitgithubdelphi

How to start with GIT in delphi (with existing code)


Since I am completely lost in this new topic, I need to ask this stupid question (as no guide covers this understandably for me).

I have:

  • Delphi code on my disk
  • a GitHub account
  • GIT downloaded and configured in Delphi IDE

What are the steps I have to do to get my code into a web-repo?

  1. create an empty repo at www.github.com

  2. clone the empty repo to my dev-machine

    a. to which folder? A blank one, or to the folder my code is in already?

What comes next?

I have played around but never got to successfully update my repos in the cloud. How can I remove the GIT configuration from my projects to start new?


Solution

  • I have played around but never got to successfully update my repos in the cloud. How can I remove the GIT configuration from my projects to start new?

    If you're asking how to start with a brand new repository and remove your current Git configurations, you need to delete the hidden folder .git from your project directory, open Git bash, and run git init. However, perform this operation only if you don't want to keep the current history of changes (if any is present).

    Instead, if you want to maintain your current repository, and you're asking how to remove the configurations to track a remote repository, you can run git remote in the Git bash and remove each result.

    # listing the remotes added to your repository
    git remote
    
    # removing each remote returned by the command git remote
    git remote remove <remote1>
    ...
    git remote remove <remoteN>
    

    Once you've brought your project to the desired state, you can go to https://github.com/ and create a new empty repository. To do that, just define the repository's name and the visibility (public or private). Do not check "Add a README.md file" or pick an option for "Add .gitignore" and "Choose a license". Once the repository has been created, copy the generated link (something in the form https://github.com/your-user/your-repo.git), open a Git terminal from your project directory, and run:

    git remote add origin https://github.com/your-user/your-repo.git
    

    Now, if you want to push your local work or fetch somebody's changes, you just need to enter:

    # pushing the current branch changes to origin remote
    git push origin
    
    # fetching the changes of another branch
    git fetch origin <other_branch>