Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I start using my repository locally and on Github?

Tags:

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?

like image 349
MEM Avatar asked Mar 25 '11 20:03

MEM


People also ask

How do I initialize a local repository?

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.

Which command initiate a git repository locally?

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.


2 Answers

That's basically correct, yes. To explain what each thing is doing...

  1. git init basically says, "Hey, I want a repository here." You only will have to do this once per repository.
  2. After that, you will want to add a remote, which GitHub probably told you to do by using git remote add origin [email protected]:username/repository This allows you to push to a remote. You will only have to do this once as well.
  3. After that, use git add to add your changes, or "stage them". You can use git add -i for a bit of a more interactive experience.
  4. Use git commit -m 'message' to commit locally.
  5. Then use git push origin master This says, "Push all of the commits to the remote origin, under master.
  6. If you make changes from another machine, or someone else makes changes, you can use 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.

like image 148
vcsjones Avatar answered Jan 05 '23 08:01

vcsjones


You're missing one step: somewhere before the last step, you need to do a git remote add origin [email protected]: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.

like image 44
Rafe Kettler Avatar answered Jan 05 '23 09:01

Rafe Kettler