Tuesday, August 13, 2013

Git setup on Mac, Linux or Unix using Terminal


Git global setup:

git config --global user.name "Bishal Ghimire"
git config --global user.email  "you@ youremail.com"

Create Repository

mkdir yourProject
cd yourProject
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin git@git.youremail.com: yourProject.git
git push -u origin master


Existing Git Repo?
cd existing_git_repo
git remote add origin git@git. youremail.com:yourProject.git
git push -u origin master


That is it ... 

Bonus Codes

Force Push Local to server

git push origin master --force


Force Pull From Server to local



# fetch from the default remote, origin
git fetch
# reset your current branch (master) to origin's master
git reset --hard origin/master



Branch and Merge




# fetch from the default remote, origin
git fetch
# create a branch at your current master
git branch old-master
# reset to origin's master
git reset --hard origin/master
# merge your old master, keeping "our" (origin/master's) content
git merge -s ours old-master

Common Git Issues And Solutions 


Issue 1 : "File Locked, unable to edit in XCode"

Solution : Change File Read Write permission 

As you have made force changes from the file from internet you are more likely to lock the files, which XCode will not allow you to edit all you can do is read the files only !
To chage that on your root folder of your terminal

sudo chmod -R 0777 ./*


Issue 2 : “fatal: remote origin already exists”


Solution :
Other 'origin' alreadt exists on remote server or is already on use

git remote rm origin
git remote add origin git@youremail.github.com:youriOSapp/my_app.git
git push -u origin --all # pushes up the repo and its refs for the first time


resync-git-repo-with-new-gitignore-file


git rm -r --cached .
git add .git commit -m ".gitignore is now working"

git-mergetool

git-mergetool - Run merge conflict resolution tools to resolve merge conflicts
Syntax - 


git mergetool [--tool=<tool>] [-y | --[no-]prompt] [<file>...]
Eg -
git mergtool --tool=emerge

Keyboard Tips 
n =  next
a / b = alter version

Read More At :

http://www.mac-terminal.com/files-and-folders/permissions/chmod/
http://stackoverflow.com/a/4787356/1294448
http://stackoverflow.com/questions/10904339/github-fatal-remote-origin-already-exists



No comments:

Post a Comment