Thứ Năm, 11 tháng 5, 2017

Adding an existing project to GitHub using the command line

My answer is not different but I am adding more information because those that are new could benefit from filling in the gaps in information.

After you create the repo on github they have instructions. You can follow those. But here are some additional tips because I know how frustrating it is to get started with git.
Let's say that you have already started your project locally. How much you have does not matter. But let's pretend that you have a php project. Let's say that you have the index.php, contact.php and an assets folder with images, css, and fonts. You can do it this way (easy), but there are many options:

Option 1

Login to your github account and create the repo.

enter image description here
In the following screen you can copy it down where you need it if you click the button (right side of screen) to "clone in desktop". 
enter image description here
You can (or do it another way) then copy the contents from your existing project into your new repo. Using the github app, you can just commit from there using their GUI (that means that you just click the buttons in the application). Of course you enter your notes for the commit.

Option 2

  • Create your repo on github as mentioned above.
  • On your computer, go to your directory using the terminal. using the linux command line you would cd into the directory. From here you run the following commands to "connect" your existing project to your repo on github. (This is assuming that you created your repo on github and it is currently empty)
first do this to initialize git (version control).
git init
then do this to add all your files to be "monitored." If you have files that you want ignored, you need to add a .gitignore but for the sake of simplicity, just use this example to learn.
git add .
Then you commit and add a note in between the "" like "first commit" etc.
 git commit -m "Initial Commit"
Now, here is where you add your existing repo
git remote add github <project url>
But do not literally type <project url>, but your own project URL. How do you get that? Go to the link where your repo is on github, then copy the link. In my case, one of my repos is https://github.com/JGallardo/urbanhistorical so my resulting url for this command would just add .git after that. So here it would be
git remote add github https://github.com/JGallardo/urbanhistorical.git
Test to see that it worked by doing
git remote -v
You should see what your repo is linked to.
enter image description here
Then you can push your changes to github
git push github master
or
git push origin master
If you get an error, try
git push -f origin master