Just another iPhone Blog
Category Archives: Utilities
I was observing a lot of traction from the developer community about the Git and Github and last year I got a chance to use the Git, majorly because of the woes we had using SVN ( subversion ) as our source control in our team where most of the members are working remotely. I was amazed to see the power of Git but the learning curve was very steep, especially if you are a long time SVN user. I chose to use terminal commands to operate Git instead of a GUI tool so that it would help me know how Git operates behind the scenes which is masked by many GUI tools out in the space.
I started preparing an Appendix of commands of myself which I would use on a daily basis and most of my usage of commands are recorded in this list. Since, Its been close to year where I have made this checklist and updated as I found new usage scenarios, I thought i would share this back to community and to the newcomers who are entering into Git world, to make their Git transition smoother.
- I assume that the readers / users of this checklist have the conceptual details on how who Git operates.
- I always referred remote repository as origin ( as most of the time I used only single repository and git names it as ‘origin’ by default ).
- I have most of the times tested these commands in Mac OS X 10.8, however I would assume you know why you are using these commands and I would not be responsible for any data loss resulting from usage of these commands.
I have organized the following commands based on the usage scenarios:
1. Basic Update and Commit
a. Check the status of git
b. Adding Files
git add <filename>
git add <regular expression>
c. Commit – only updates the Local repository and does not push to the cloud
git commit -am “Commit Message”
git commit -m “Commit message” <filename>
d. Update to remote repository
git push <remote name> <branch>
By Default <remote name> would be origin, if no branch is specified, then it will be pushed to master.
2. Remove from staging == remove from svn tracking
git rm -r –cached <file path>
3. Git Branch
a. Creating a branch
git branch <branch_name>
git checkout -b <branch_name>
b. List all branches
c. List all branches in remote repository
git branch -r
git fetch && git branch -r
d. Merging a branch
1. To commit and push all the changes made in this branch to remote
//Commit all the modified files
git commit -am “<Commit message>”
git push origin <branch name>
2. Switch to destination branch where u need to merge your changes.
For eg. If you want to merge in Feature 1 in master branch, then switch to master by ‘git checkout master‘
git merge <branch_name>
git merge –no-ff <branch_name>
c. Deleting a branch in local repository
git branch -d <branch name>
d. Deleing a branch forcefully on local repository
git branch -D <branch_name>
e. Deleting a branch on remote repository
git push <remote> :<branch _name>
f. Download a branch from the repository
(sometimes you need to execute ‘git fetch’ command before executing this command )
git checkout -t origin/<branch-name>
4. Ignore New Files or Never track
– Place .gitignorefile in Git root directory
– Add the file path or wilde cards for e.g., *.xcodeuserstate entry for example using vi editor or any text editor. You can add each file to be ignored in a new line
– save the .gitignore file
– this will take effect only to the new files. if you want to ignore an existing file. do a git rm –cached <filename> and follow the above steps.
Please let me know through comments in this blog if there are any faulty usage of these commands, so that I could rectify it.
I will try to update this post as and when I find some new commands. Please let me know if you find this useful.
Happy Coding 🙂
A Snippet to calculate an Image Size to fit within a given rectangle with its Aspect Ratio maintained
ImageSize NewSizeForImageOfSize(ImageSize srcImageSize, ImageSize destSize)
if( srcImageSize.width > srcImageSize.height)
newSize.width=destSize.width; newSize.height= srcImageSize.height * (destSize.width/srcImageSize.width)
newSize.height=destSize.height; newSize.width= srcImageSize.width * (destSize.height/srcImageSize.height)