Assuming you have a repos on github already, issue the following commands:
cd existing_git_repo
git remote add origin git@github.com:[user]/[reponame].git
git push -u origin master
The instructions. Basically,
git config --global user.name "Your Name Here"
git config --global user.email "your_email@youremail.com"
Then download and setup git-credential-osxkeychain.
curl -s -O http://github-media-downloads.s3.amazonaws.com/osx/git-credential-osxkeychain
chmod u+x git-credential-osxkeychain
Issue a which git and note the path of git. Assuming it is /usr/bin/git, you have have to move to /usr/bin/ (IMPORTANT: less the git part!).
sudo mv git-credential-osxkeychain /usr/bin/
One of the most important configuration
git config --global color.ui true
With that, commands like git diff and git log -p looks better
Sometimes, you want to see what are the changes in your working directory (compared to HEAD/the last commit).
git diff somefile.py
Or you want to see what are the overall changes between the last 2 commits
git whatchanged -n 1
Then the actual code changes
git log -p somefile.py
If you have added new files or updated tracked files
git add .
If you have deleted files or updated tracked files
git add -u
You could do both in a single step
git add -A
To know,
cat .git/config
Or you can list the remotes
git remote -v
It’s a 2 step process. First you fetch the changes from a remote named origin
git fetch origin
Then you merge a branch master to local
git merge origin/master
Or Simply
git pull origin master
If origin is a default remote and ‘master’ is default branch, you can drop it eg. git pull.
This always happen when you work in teams. A very commmon question.
It usually goes like this.. You tried to update
git fetch
git pull
... not uptodate. Cannot merge.
So you commit your local changes
git add .
git commit -m "some changes"
...
Automatic merge failed; fix conflicts and then commit the result.
So you need to resolve the conflict
git mergetool -y
At this point you use the GUI (eg FileMerge) to resolve the conflicts and save. Then you commit
git add .
git commit -m "fixed conflicts"
git push
Done!
Say when you have a merge conflict, you know it should just take your file,
git checkout --ours filename.c
Or if you know yit should be their file,
git checkout --theirs filename.c
Useful when you want to tag a version.
git tag -a v1.2
If you want to push to the tag, it works similarly like a branch.
git push origin v1.2
This is usually when you accidentally commit wrongly.
git log
git reset --hard <sha1-commit-id>
git push origin HEAD --force
Read this cheat sheet. You will learn shortcut keys and referencing issues easily.