Git is a distributed version controlling system created to manage the Linux kernel. Few advantages are,
- Efficient management of large projects
- Support for distributed development
- Support for non-linear development
Even though git is managed by several user interfaces , Command line is the most common way to interact with Git.
If you are in the mac , download the dmg file and double click on it.
After the installation open a new command prompt and run the following command to test the installation,
output should be something like
git version 220.127.116.11 (Apple Git-33).
Initialize the Git Repo
If you are in the mac environment,
- Open the terminal first,
- create a directory called “test-git” in Desktop.
- move your cursor into the created folder.
- Add a file called index.html
<!DOCTYPE html> <htmllang="en"> <head> <title>Title tag</title> </head> <body> <p>This is a test git page.</p> </body> </html>
This is just an html page for our purpose to test the git functionality. not just to teach you html.
Now you are in the /Desktop/test-git folder,
Run this First ever git command to initialize.
Current directory is now going to be a powerful Git Repository.
Now you can watch there is a .git directory in your current folder.
Note :- Deleting “.git” folder will turn your repository into normal unversioned directory of file.
Check the git status
you will get the response of
Initial commit Untracked files: (use "git add <file>..." to include in what will be committed) index.html nothing added to commit but untracked files present (use "git add" to track)
Staging mean, what files to include in the next commit. Git does not track files automatically. We have to add the files manually to git.
git add index.html git status
We have just added index.html for the next commit.
Committing the changes to the local git folder done by the following command.
git commit -m "[message]"
When you enter this command you will be asked to type the message for the changes you have done for the commit.
View Git history
to check the history of the work.
git log --oneline
the above command will give you structured log of the change history. There are so many commands that we should practice. To learn more about git commands click here.
Setting Your Name and Email in GIT
To identify or differentiate your commit from other commit in your team, we should update our name and email globally or specifically to the git project.
To update your name
//setup a name for your current git project. $ git config user.name "Apps Git"
//to setup your name globally for all your projects in your pc. $ git config --globally user.name "Apps Git"
//To setup your email in git $ git config user.email "firstname.lastname@example.org"
//to setup email globally $ git config --global user.email "email@example.com"
Git Source Control with xCode 8.0++ in
iOS 10.0 Applications
We have setup GIT Source control to the pc. Now we will learn in a simple and step by step way, how to work with GIT in Xcode projects in iOS 10.0+ applications.
To open Xcode using keyboard short cut, Press (Command + Space Bar) and type “Xcode” and press enter button.
Create a new project in Xcode and goto next page to select a directory to save the project. You will notice a checkbox like below to initiate a GIT Repository. check it.
Now project is ready with local empty git repository. We can add files to repository or remove.
Commit Files to Local Repository
Well initial commit willbe done by the Xcode it self. If you goto
Top Menu -> Source Control -> History
You can see the Initial commit like below.
We will add our first commit to the Repo,
Edit any of the view controller and save the file. You will notice that there is a “M”
mark next to the file name in the left Navigator.
You made a change to a file, Lets commit it by click the button in the,
Top Menu -> Source Control -> Commit
Xcode has great built in support for Git.
- You can check/uncheck the file from the commit.
- You can select/unselect a change from a file that is selected for commit.
- type your commit message.
You can check commit history by going
Top Menu -> Source Control -> History
To check the modified files of a commit,
- Open the Commit History page.
- Click the button which is located next to commit message
Congratulation! You know how to successfully use Git with Xcode. Next we will look how to upload the fresh Xcode project to remote GitHub account.
Upload Xcode Project to Github Remote
- Sign in to your GitHub account and create a new Repository.
Note : Don’t Add .gitignore file or README file while you create repository. You can add them later.
2. Copy the remote url.
3. Goto Config page of the local branch and add the url
Goto Remote tab.
Press “+” button in the bottom left right side
Select “Add Remote” button.
After you added the url, type your username and password of your GitHub account to verify your account.
Now push the commits to the remote.
Thats all, You are done now. To verify the changes login to remote GitHub by browser and check whether changes are uploaded to the server.
If you guys want to work with Any other Git client side tools other than default Xcode built in support, I would suggest you to download and install SourceTree
I will cover The SourceTree guide in another tutorial.
I will get back to you with some other useful blogs soon.
Self Taught iOS & Android Mobile Application Developer.