Git and GitHub Overview

Git is a free and open-source distributed version control system.

Install git and create a GitHub account

  • more about how to install git – here. There is a GUI option to use git, but I would recommend start (and probably stick with CLI)
  • Create GitHub account here

install git in Linux:

sudo apt install git-all

Set your user name and email address

every Git commit uses this information, and it is been added into the commits you start creating:

git config --global "Dmitry Golovach"
git config --global

Create a local git repository (project folder)

mkdir sandbox
cd sandbox
git init

Initialized empty Git repository in /home/cisco/sandbox/.git/

The idea: make changes in the repository, if it is in the state we want to record – commit.
Each file in the working directory can be in one of two states (check the status with git status command):

  • tracked
    • git knows about these files
    • can be unmodified, modified, or staged
  • untracked
    • everything else

The idea: change files – selectively stage these modified files and then commit all those staged changes

Once we add a new file – it will be untracked (it is new and uknown for git), but git recognizes that new file was added:

Staging environment – git add

To add a file to a commit, we first need to add it to the staging environment using git add command:

Commit – git commit

Now files are ready to commit using git commit -m “message” command. It’s good to add a comment about what has been changed in this commit.

If we need to keep track of own code locally – don’t need to use GitHub. But it is always good to have a copy of repository somewhere else or for work in team => GitHub

GitHub – git push

Create a new repository and you can keep it Private (later change it to Public) or Public:

Quick notes how to work with GitHub:

push the commit in your branch to your new GitHub repo.

Note: if you have 2FA enabled (you probably should), follow the “Creating a personal access token for the command line” to use a Personal token as a password:

git remote add origin
git push -u origin master

As result files have been pushed to the GitHub:


Work with repository and files, once done

#Add the file to your local repo. Files are ready to be committed
git add <filename>

#Remove from staging (unstage)
git reset HEAD <filename>

#Commit the tracked changes. Files are aready to be pushed to remote repo
git commit -m "message"

#Remove commit and modify the file
git reset --soft HEAD~1

#Push the changes in your local repo up to the remote repo
git push -u origin master


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *