Tech
Adding an existing project to GitHub using the command line
- Create a new repository on GitHub. You can also add a gitignore file, a readme, and a license if you want
- Open Git Bash
- Change the current working directory to your local project.
- Initialize the local directory as a Git repository.
git init
- Add the files to your new local repository. This stages them for the first commit.
git add .
- Commit the files that you’ve staged in your local repository.
git commit -m "initial commit"
- Copy the HTTPS URL of your newly created repo
- In the Command prompt, add the URL for the remote repository where your local repository will be pushed.
git remote add origin remote repository URL
git remote -v
- Push the changes in your local repository to GitHub.
git push -f origin master
That’s all
This page is brought to you thanks to our main sponsor Collaboard.
Collaboard is an online real-time whiteboard that allows you and your team to exchange ideas and to go beyond the limits of a virtual meeting. Start thinking differently together and drive innovative results. Bring collaboration to the next level!
Give it a try, there is also a 100% free subscription.
Nice. straight to the point
Loved this article. It could be improved by slightly changing the formatting of the second command in step 8 a little bit so that its easier to tell which parts are part of the command and which parts are placeholders. For example: ‘git remote add origin remote_repository_URL’.
Grazie mille! 🙂
You are a saver of lives Gian.
Thank you
From my DOS command line I ran the following command
git remote add origin remote repository https://github.com/myname/reponame
and I received the following error
usage: git remote add []
-f, –fetch fetch the remote branches
–tags import all tags and associated objects when fetching
or do not fetch any tag at all (–no-tags)
-t, –track branch(es) to track
-m, –master
master branch
–mirror[=]
set up remote as a mirror to push to or fetch from
nice clean & easy!
Thank you
git remote add origin remote repository URL
should be change to
git remote add origin URL
Thank you it works perfectly
thanx. with your guidence i finish it.
It should be formatted better 😉
git remote add origin
Thanks so much, so simple … Although while trying out commands I skipped git remote -v
by mistake.
After git remote add origin remote repository URL
Directly entered git push -f origin master
It worked though.
So what’s the use of git remote -v
Thank you!
Hi,
The line,
git remote add origin remote repository URL
Is a bit confusing, it would be clearer it if read
git remote add origin URL
Thanks!
thanks for turoial
I stucked in step 7.. How I get the new URL created after run commit command?
Thanks
Thanks
“add the URL for the remote repository”
Like, literally the URL of the repo? That’s not what this SO answer implies … https://stackoverflow.com/a/55314654/3899919
Thanks so much for this cheat sheet! It was very helpful.
Thank you !
I wasted so much time trying to use git push -u…
thanks this helped
Thank You!
It works fine.
Easier and better than everything else.
But be careful with these commands!!!
Hi,
well, it’s a somewhat old article, but I wanted to leave a thank you.
Maybe the part ‘git remote add origin remote repository URL’ will be more clear if you put ‘remote repository URL’ into quotes. As a newby I made this mistake 🙂
Great quick little hint! I would update the post this way to avoid some confusion:
8. In the Command prompt, add the URL for the remote repository where your local repository will be pushed.
git remote add origin remote-repository-URL
I don’t know enough git to even be dangerous so it took me a minute to figure out “remote repository URL” wasn’t a list of git commands.
Really Helpful! Thank you!
Be careful with the force flag -f
This will overwrite anything already existing in the repo!