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.
- Jump into your project’s folder in Terminal
$ cd your-project-folder-path
- 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
- 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.
- $ 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.
- Now that the .gitignore is ready so you can add all the untracked files to the staging area
$ git add .
- 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.