[github] add existing project to github

Background : Add an existing local project to github repository.
Although the github’s helping article Adding an existing project to GitHub using the command line is very complete, but it existing alwarys some errors.
And I will try to add some chinese translation some command just for understanding.

So the mainly procedure is 主要过程:
1. Create a new repository on GitHub.

2. Initialize the local directory as a Git repository.

git init

3. Add the files in your new local repository.

git add .

4. Commit the files that you’ve staged in your local repository.

git commit -m 'The comment for your commit'

One thing you have to know here is that, commit is just record your local changes to the project, but the changes hasn’t been combined with your remote project.

5. Get the remote repository URL. For me, this’s https://github.com/cupidcb/cuiborails.git.

6. In Terminal, add the URL for the remote repository where your local repostory will be pushed.

## This gonna to set the remote repository "origin" 
git remote add origin https://github.com/cupidcb/cuiborails.git 

## see your local
git remote -v
## I got this :
#origin	https://github.com/cupidcb/cuiborails.git (fetch)
#origin	https://github.com/cupidcb/cuiborails.git (push)

7. Push the changes in your local repository to GitHub.

git push origin master 

This command will finally combine your local change of your branch “master” with remote repository “origin”

For more details, you can find the commands in github

what I want to mention is the no-fast-forward error, When I tried the last step push :

git push origin master 

Screenshot from 2014-06-01 16:43:20
This is probably because there is another change made in remote repository that you haven’t checkouted and merged in your local branch before you make changes.
So what we have to do is :

## Fetches updates made to an online repository
git fetch origin
## Merges updates made online with your local work
git merge origin branch

Or to do it simply, we can just do a “pull” which will do a fetch and merge in the same time.

git pull origin branch

Find github’s Dealing with non-fast-forward errors.

Finally I found a nice picture better explain git workflow from here:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s