Post Date: September 21, 2018
Last Updated: September 24, 2026
Introduction
Git is a distributed version control system used to track changes in source code and manage software development projects efficiently. It allows developers to maintain different versions of files, collaborate with team members, and synchronize changes between local and remote repositories. This tutorial provides an overview of commonly used Git commands and explains the basic Git workflow, including creating or cloning repositories, staging changes, committing changes, viewing history, and working with remote repositories.
Prerequisites
Before following this tutorial, ensure that you have the following:
- Basic knowledge of Linux command-line operations.
- A Linux-based system such as Debian/Ubuntu or CentOS/RHEL.
- Sufficient privileges to install software packages.
- Git installed on the system.
- Access to a Git repository for practicing clone, pull, push, fetch, and merge operations.
- Basic understanding of files, directories, and source-code management.
Implementation
Step 1: Git Installation in Linux:
For Debian Linux based environment use this command line.
● apt-get install git
For Centos based environment use this command line.
● yum install git
Step 2: Git Configuration:
# git config --global user.name "Name Surname"
# git config --global user. Email name.surname@xyz.com
Step 3: Getting Git Repository:
- To clone an existing repository from server 2:
If you want to get a copy of an existing Git repository, use git clone [URL].
git clone user@server:/path.git
# git clone username@/10.1.1.1:/usr/local/blog01.git
- To start tracking new/edited filename(add single file at a time).
# git add filename
- Let’s start tracking all changed/new files(add multiple files at a time).
# git add. (git add -A)
- Save changes to the local repository.
# git commit -m 'Commit message’
Step 4: Recording changes to the repository:
- status
# git status
Step 5: Recording changes to the repository:
- Tracking our files.
- To Begin tracking a new file (directory).
# git add
Step 6: Recording changes to the repository:
- Staging modified files.
- To Stage the file, add this content to the next commit.
#git add
Step 7: Viewing staged and unstaged changes:
- To view what changes but not yet get staged ,So that diff command is used.
#git diff
Step 8: Recording changes to the repository:
- To commit your changes to the local repository.
# git commit
Step 9: To Viewing the commit history:
# git log
Step 10: Working with remotes:
- Fetch: To fetch all the information you don’t have from remote repository, no automatic merging occurs here.
#git fetch
- Merge: To automatically merge data from remote with your repository data.
#git merge
- Pull: To fetch and merge automatically.
- pull = fetch + merge
#git pull
- Push:To push your version to the server.
$ git push origin master
Good Note:
Git won’t allow you to push to the remote that is ahead of your version:
At first needed to fetch. Otherwise, show a error as follows,
![rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'http://gituser/XYZ.git'.
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Now we have practised some basic git commands. We hope it will be useful for beginners. Write to us in the comment box for any suggestions. Thanks in advance.
Conclusion
Git provides a simple and effective way to track changes, manage different versions of files, and collaborate with others. In this tutorial, we covered essential Git commands such as git clone, git add, git commit, git status, git diff, git log, git fetch, git merge, git pull, and git push. Understanding these fundamental commands and the Git workflow provides a strong foundation for working with Git repositories and managing development projects efficiently.
FAQs
1. What is Git?
Git is a distributed version control system used to track changes in files, manage different versions of a project, and support collaboration between developers.
2. What are the three main states in Git?
The three main states are Modified, Staged, and Committed. Modified files contain changes, staged files are prepared for the next commit, and committed changes are stored in the local Git repository.
3. How do I install Git on Linux?
On Debian/Ubuntu-based systems, use apt-get install git. On CentOS/RHEL-based systems, use yum install git or the appropriate package manager available on the system.
Related Articles
Talk to our experts
Looking for the right technology solution for your business?. Our experts can help with web hosting, domain registration, DevOps and cloud, software development, web applications, mobile applications, and enterprise solutions. Get in touch with our team here.





