How to start working with Git and GitHub

Version control systems for today are almost mandatory for any project. One of the most popular version control systems is Git. Consider working with Git in conjunction with GitHub – the largest hosting server for the deployment of IT-projects of joint development. GitHub allows publishing open source projects for free.

In this article, we start to work with Git and GitHub on the Windows operating system.

What we need, in order to start our work with Git:

  1. Download the Git distribution for windows:
  2. Install Git on the user’s computer
    1. All installing options can be set “by default”

  1. After installation Git on the local computer, you need to make its interaction with the GitHub server. This can be done with several protocols, but we will only consider data exchanging using the ssh. Only this protocol allows both to receive project data from the server, and to send changed data to the server.
    1. First, we need to generate ssh keys to authorize on GitHub. This can be done using the Putty program.
      1. Run puttygen.exe
      2. Create a private key. This is the user key.
        1. Press “Generate”
          1. Move the mouse to generate a unique key
          2. For better protection of the key, you can enter a password, but then this password will need to be entered everytime you start working with Git.
          3. In the main menu choose Conversions – Export OpenSSH Key
            1. Save the key in a file with *.pem extension
      3. Create a public-key. This key will be set on the GitHub server.
        1. Open the site in your browser
        2. Create a developer account (if you do not already have one).
        3. Sign into your account
          1. Profile – Settings – SSH and GPG keys
            1. New SSH key
            2. Fill the fields with:
              1. Title: empty
              2. Key: copy here the text from puttygen.exe from the field “Public key for pasting into OpenSSH authorized_keys file”
            3. Save the public key.
  2. All the work with Git will be conducted from the command line console. For convenience, you can install a graphical shell, like TortoiseGit, but there’s nothing too complicated from working with the Git console.
    1. Run the Git Bash command shell by clicking on the shortcut created during the installation.
  3. To get started with Git, you need to do minimal initial settings

Checking the current settings:

First, you need to specify the user name and email (you need to specify your own):

  1. To exchange data between the local Git and the remote GitHub server, you need to configure the ssh-agent autorun when the Git Bash shell starts and register the previously created private key for authorization.

Create a .profile file in the c:/users directory/user_name by executing the command in Git Bash:

Add the following text to the created file: (starting the ssh-agent and registering the private key from the specified path). You need to specify the correct path to the private-key created earlier.

The setup is completed, now we can start working on the project.

  1. Create a new empty project on the GitHub site and clone it to the local user’s computer:

Sign into the GitHub and create a new project. In order to get its local copy on the user’s computer – you need to clone it. Create a directory for your projects on the local computer. Move to it in the Git Bash shell:

From the GitHub project get the path for cloning. Go to the project on GitHub and click the “Clone or Download” button, select “use SSH” and save the proposed path. It will look like something this: Ivanov/Test_project.git

Next, in the Git Bash shell, you need to execute the cloning command, specifying the project path.

As a result, the Test_project directory will be created in your projects place on the local computer and project files from the GitHub will be downloaded to it.

  1. Let’s start working on the project itself:

Move to the project directory:

To get information about the state of the remote repository (project on the Git Hub website) execute the following command:

Whenever you start working on a project, first of all, you need to get all the changes from the remote repository (in our case – the project on the GitHub website). This is necessary to work with the current version of the project code:

After the data in the local project directory is updated, you can start working with the code – make changes, additions, create and delete files, etc.

  1. After you finish working with the project code, you must send all the changes to the remote repository.

In order to see if there were any changes that you would send to the remote repository execute:

If a new file was created (its name will be in the “untracked” section when executing git status), add this file to git (index it):

Fixing changes in the local copy of the project (with a blank comment, the changes will not be fixed):

Sending the committed changes to the remote repository:

  1. Excluding files from working with Git.

If you want certain specified files not to be sent to the remote repository – create a “.gitignore” file in the project directory and add it to the project:

Put the files and directories paths to this file, which should not be uploaded to the remote repository. For example, for a Python project (PyCharm IDE), the contents of .gitignore can be such (the specified directories will be ignored):

Commit .gitignore and send it to the repository:

  1. If the project is published, anyone can not make any changes (except the simplest ones) in it not to damage the published code. So any work with the published project should be based on the use of “branches”. “Branch” is a separate copy of all project files, into which you can make changes and which can be further merged with the main project after all changes completion, or deleted without consequences for the main code of the project if necessary.

Create a new branch (Git will switch to it). Instead of “branch_name”, you must specify a unique name for the new branch.

Now we must commit and upload to the remote repository only this branch (in the remote repository this branch will be automatically created):

When the work with this branch is finished, we need to merge this branch with the main code. To do this, switch to the branch to which you want to merge (master), merge current and finished branches, delete the finished branch, commit changes, update the code on the remote repository, and delete the finished branch on the remote repository:

If you do not need to build is this branch to the main code, you can simply delete it without merging:


0 0 votes
Article Rating
Notify of
0 Комментарий
Inline Feedbacks
View all comments