DEV Community

Sharonah8
Sharonah8

Posted on

Introduction to Git and Github.

Git is a version control system that is extensively used by programmers all over the world. It assists individual developers in monitoring their changes as they work on various features within the same project, as well as teams in organizing their code. Github works hand in hand with Git which is an online application that lets users host, examine, and collaborate as teams.
In Github, we make use of commands to carry out certain processes. Some examples of command include git –version, git push, git add etc. We shall look at these and more commands and the different roles that they play.
In order to create a new project on Github, you will need to create a new repository. Then clone it to your machine and commit and save changes to the file you are working on. You will then push these changes.
There are numerous git commands. Some of the most common ones include:

Git config – sets your username and email address to be used within your commits.
git config –global user.name “JohnDoe”

git config –global user.email “johndoe@example.com

Git init – Initializes a new repository.
git init [repository name]
Git add – Adds a file to the staging area.
git add newproject
Git add * - Adds one or more files to the staging area
Git clone – Used to obtain a repository from a URL
git clone [url]
Git commit – Saves the changes in your local repository
git commit -m “[Commit message]” Your commit message must be descriptive. It must describe the actual changes that you’ve made.
Git commit -a – Commits the files that you added using the git add command and any other files that have been added since then.
git commit -a
Git push – Pushes the changes in the committed file from the local repository to a remote repository so that other people are able to access them.
git push [variable name] master
Git pull – Fetches the last changes saved on the remote repository and pushes them into the local repository.
git pull [Repository Link]
Git merge – Merges your branch with the parent branch.
git merge [branch name]
Git status – Gives you the current status of your working directory.
Git log – to view the changes made
Git diff – gives you the difference between what you have in the current directory and what has been committed

These are just a few of the git commands. There are many more commands that one needs to learn. Worry not, as these can be found online. And the more you work with Git, the more you’ll be able to learn and master these commands. Remember, practice makes perfect!

Basically, the work flow in Github is as follows:

  1. Create a repository.
  2. Clone it to your local machine.
  3. Commit and save the changes after adding a new file.
  4. Push these changes.
  5. Use git to make some changes to your file.
  6. Pull these changes on to your local machine.

Top comments (0)