Adding Git to an Existing Project

I would do it for Xcode project but it can be done almost similarly with any other project.

Before adding git, you should configure git with your name and email address so that your changes are tracked properly. GitHub uses the email address you set in your local Git configuration to associate commits with your GitHub account.

  1. Jump into your project’s folder in Terminal
    $ cd your-project-folder-path
  2. View items of project folder
    $ ls -la
    There won’t be .git folder if it is not already under git source control. Or it can also be verified whether it is already under git source control with the command
    $ git status
  3. Initialise git repository
    $ git init
    Initialized empty Git repository in /your-project-folder-path/.git/
    It shows that the Git repository is empty so need to add files to be tracked but we don’t want to track down every files like specific to OS or the ones created automatically. Here we need to exclude the files specific to OS X and specific to Xcode by defining rules in .gitignore file.
  4. $ vi .gitignore
    This command will open vi editor and paste the following contents and save it. The file .gitignore can itself be ignored but it is better to keep it being tracked so that other users can use the same settings to avoid commenting unwanted files.
    # Xcode
    .DS_Store
    */build/*
    *.pbxuser
    !default.pbxuser
    *.mode1v3
    !default.mode1v3
    *.mode2v3
    !default.mode2v3
    *.perspectivev3
    !default.perspectivev3
    xcuserdata
    profile
    *.moved-aside
    DerivedData
    .idea/
    *.hmap
  5. Now that the .gitignore is ready so you can add all the untracked files to the staging area
    $ git add .
  6. Now make your first commit of tagged files.
    $ git commit -m “Initial commit.”

Now you would like to use some code repositories to secure your coded inventions.

Advertisements

One thought on “Adding Git to an Existing Project

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s