How to get remote repository and commit files in git

Git commands that are commonly used for managing project files such as ‘init’, ‘add’, ‘commit’, ‘status’, ‘log’.

 437 total views

Git commands

The last Git article illustrates how the git version control system works. This article will help you to learn how to get a remote git repository and commit files in git. You also get knowledge about git basic commands for remote repositories and commit files in git repository as local.

Getting a git repository

To get an existing git repository either from the local system or online repositories such as Github, bitbucket we can use the ‘clone’ command.
The format for getting a repository is as follows

$ git clone 

For example, consider the following syntax

$ git clone https://github.com/example.git

Initializing a repository

Initializing a repository refers to initialize the repository which is needed to be git i.e to be tracked. This is done using the ‘init’ command.To initialize a repository use the following command

$ git init

Go to the folder you need to be tracked and execute the ‘init’ command.
This creates a new file called .git the file that is where the git keeps of the files that are stored in it in the form of encryption.

Next, we need to stage the files that need to be tracked. This is done using ‘add’ command. The staging files refer to set the which files in the repositories are needed to be tracked in the git.
To stage a file

$ git add README.md

Instead of README.md replace with the file name needed to be staged.
To stage all files specify ‘.’ to add all files in the repository.

$ git add .

Next, we need to commit the files that was staged using the ‘commit’ command.

$ git commit

To commit the files we need to specify commit messages for all commits using ‘-m or –message’ specification in ‘commit’ command.

$ git commit -m 'Added new files'

Tracking a repository

To track the file status we can use ‘status’ in the git command.

$ git status

The status will show you the changes that are changed if any as follows.

On branch master
Changes not staged for commit:
    (use "git add ..." to update what will be committed)
    (use "git checkout -- ..." to discard changes in working directory)
        modified:   README.md
no changes added to commit (use "git add" and/or "git commit -a")

If no changes are made in the files it displays the message as follows

On branch master
nothing to commit, working tree clean

To view the log of the files committed to the git we can use the ‘log’ command.
This log command will give you all the logs about the commit done to the files in git.

$ git log

This will output the log as follows

commit 9222b1d10ed1741a2e7ddde50a264a729dc9c85d (HEAD -> master)
Author: AjeethT 
Date:   Thu Jul 16 15:48:54 2020 +0530

The first line gives the commit hash value next it specifies the branch as a master. Next are the author’s name and the timestamp of the commit.

The full flow of the git operation are as follows:

$ git init
$ git add README.md
$ git commit -m 'Initial commit'
$ git status

In the next git post, I will be sharing on different operations on the git repository.
Click here for Git archives.
To view official git documentation please visit git docs.

As I’m new to the blog, I trying to improve the contents daily. Please support it through comments.
If the article is helpful or any thought please comment on me.

 438 total views,  1 views today

Leave a Reply

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