Connecting Git and Github

  1. Create a new repository on GitHub. To avoid errors, do not initialize the new repository with README, license, or gitignore files. You can add these files after your project has been pushed to GitHub.
  • Change the current working directory to your local project. cd /Users/admin/source/repos/

Initialize the local directory as a Git repository: “git init” . You should read up on the documentation of the initialization of https://git-scm.com/docs/git-init

You can either create a new repository (as in the example below) or initialize an existing directory as a git repository.

Using git init to create a new Repository
You will be able to see the new repository in File Manager

Once the repository is created or initialized you will see a hidden .git directory. This is all part of the mechanics of version control and the features of git.

The contents of the .git directory.

The working directory of your git directory in this example is NewRepository. This will be whatever directory you created or initialized with git. If you right click on the directory you will see options to Git Gui or Git Bash (they both do the same thing just one is command line and the other is a GUI version).

Here is the Git GUI interface

Now you are going to have some files in this directory. That is kind of the point of using git. These can be programming files (code) or other types of files. You will be adding these files to your repository. This is the git add command and you will also want to know the use of this command https://git-scm.com/docs/git-add

git add . #adds all the files in the repo and stages them for commit.

You are now ready to commit the files to the repository. This is done with the git commit command. As with the other commands it is worthwhile to read the documentation to know what it does. https://git-scm.com/docs/git-commit

use of the git commit command.

Now you can go into Github (you should have an account), create a new repository and either follow the instructions there or the instructions here – they are the same.

Creating the repository in Github
Results of creating the repository in Github

Now you will be able to push your information from your local git to the remote version at github. Congratulations you now have a code managed repository.

Using git remote add origin

You can view your repositories in github

Repositories in the github account.

There are some commands you will want to know such as git remote, git push, git fetch

Some git commands