So:
1) I have created my account on github and I've created a repository there.
2) I have the keys to access the repository from my dev machine to github, using SSH, so that my local repository is synchronized with the remote one hosted on github once I do, push or pull.
But, I'm not understanding how will all this start.
I have my local files on this dev computer and from there I do:
3) git init
then
4) git add
and then I 5) commit that project to my LOCAL repository.
Once this is done, then I will 6) push this to github repository.
Is this correct?
Initializing a new repository: git init To create a new repo, you'll use the git init command. git init is a one-time command you use during the initial setup of a new repo. Executing this command will create a new . git subdirectory in your current working directory.
The git init command creates a new Git repository. It can be used to convert an existing, unversioned project to a Git repository or initialize a new, empty repository.
That's basically correct, yes. To explain what each thing is doing...
git init
basically says, "Hey, I want a repository here." You only will have to do this once per repository.git remote add origin git@github.com:username/repository
This allows you to push to a remote. You will only have to do this once as well.git add
to add your changes, or "stage them". You can use git add -i
for a bit of a more interactive experience.git commit -m 'message'
to commit locally.git push origin master
This says, "Push all of the commits to the remote origin, under master.git pull
to get them from the remote.You might want to consider reading ProGit - it's free online and is a wealth of information. There you can learn more about features like branching, merging, etc.
You're missing one step: somewhere before the last step, you need to do a git remote add origin git@github.com:username/reponame
so that Git knows where to push your repo when you say git push origin master
. Otherwise, you've got it! You may want to check your work with git diff
before you commit, though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With