Common Git Commands to Master

Common Git Commands to Master

Table of contents

No heading

No headings in the article.

Git is a necessary evil for newbie developers. while working with the Command Line Interface may not be your worse nightmare, it sure scares the crab out of most people that are yet to wrap their heads around it.

Not familiar with Git CLI commands?

Nothing to worry about here. In this article, I am going to work you through some basic git commands to get you started. You may want to sign up on GitHub if you have not done so already.

Before you begin using git, you have to download and install it on your system. You can get it here

1. config: For you to be able to connect your remote git account to your local repository, you need to, first of all, configure your local machine. the most common configuration options are name and email. to do this, run the command below in your terminal.

git config --global <username>
git config --global <email>

The username and email must correspond to the ones you used in signing up on GitHub.

2. init: Navigate to the folder containing your project and run the command below.

git init

This initializes your local folder as a git repository which enables git to track the changes in it and all the files and subfolders it contains. Now you can virtually create different versions of your project

3. clone: The easiest way to work with git is to create your repository remotely, then clone to your local system. This will save you the headache of trying to add and link to a remote repository locally.

git clone <the URL to your repository on git hub>

4. add: To save the changes made to your project, you have to stage it.

git add -A


git add .

This will save all the changes made in your current repository. you can also stage just a single file by specifying the file name.

git add <filename>

5. commit: Now that you have staged your changes, running this command will make git take a record of the state of your repository or file at that particular time. It is like creating a picture of what your project looks like at that instant. You can refer back to a commit to edit, delete, or undo changes.

git commit -m <Title of your commit message> -m <message>

The title argument is optional. The message should be concise and clear as to plainly explain what that commit is all about.

6. push: Finally, assuming all went well up to this point, you can make the local repository available remotely. Ensure that you have staged the repository or file and have committed it with a good message.

git push

On the other hand, If you created and initialized your repository locally, you will need to point it to the URL of the remote repository you want it to be linked to by first of all running the git command;

git remote add origin <URL>

If the origin doesn't yet exist, it will be created.

Alright, folks. That's it for this article. please do reach out to me if you have any questions:

Thanks for reading.