Symas employee?Sign in

← Knowledge Base

Reference

Git Commands and GitHub

Git is a version control system that is used locally and can track and store different versions of a project in development. Its commonly used counterpart, GitHub, is a remote storage for hosting and sharing the code. This article will explain some commonly used commands for operating git and communicating code between local Git repositories and remote GitHub repositories. 

Installing Git and Cloning a GitHub Repo

First choose the appropriate package management system, and install git locally, e.g.:

Fedora/RedHat/Centos:

sudo dnf install git-all

Debian/Ubuntu:

sudo apt install git-all

Next import (clone) the remote repository from GitHub to your local folder in order to work with it:

  1. Find the repository page online on GitHub
  2. Click on the green button that says “Code” and copy the repo's URL
  3. In your command line navigate to the desired location for your local repository 
  4. Clone the remote repository to the local location:
git clone 

The folder structure from the GitHub repo will be copied.

Making Changes and Committing Them

In order to create a “version” the changes made need to be staged and then commited:

1. Check the status of your local repo. The git status command:

git status

will list all files that have been updated and/or staged. 

2. Select the files (changes) that you want to be committed. Use:

git add 

to stage a changed file. If you have a staged file that you don't want to commit use

git restore 

3. Run: 

git status

again to make sure those (and only those) files that you want to be committed are staged.

4. Run:

git commit 

to commit your staged changes. You will be directed to add a commit message. Alternatively you can use:

git commit -m “” 

as a shortcut.

5. You can check your commit history by running:

git log

 

 

 

 

 

Pushing and pulling changes between local and remote repositories

To push your local commit onto the remote GitHub repository run git push command. You will need to specify the remote name - typically “origin”, and the branch name - by default “main” or “master”. 

git push origin master

To pull changes made on the remote GitHub to your local repository use git pull

 

For more information including information about branching please check the official documentation on https://git-scm.com/docs