How To Use Git Effectively Part 1
Posted By : Satish Thakur | 23-Dec-2018
How To Use Git Effectively [Part 1]
- This code was working yesterday but today it is not
- The code got deleted
- A weird bug has introduced suddenly and no one knows how?
If you have been in any of the above
Question: What is git?
- First of all, Github is not git. Many people confused between them.
- Github is a website for hosting projects that use git using git basic commands.
- Git is a type of version control system(VCS) that makes it easier to keep track of changes to our files.
- For example, when you edit a file, git commands can help you determine exactly what changed, who changed it and why?
Question: Why Git?
Question: What does Git do?
Git tool does two main things:
- Track the history of your files.
- Share and collaborate on files.
Question: What is the operation
Some basic operations in Git are:
Some advanced Git operations are:
[Note: Assumes that you have
1. Configure Git :
After git is installed on your system, configure git so that you can understand who is pushing the code to the remote repository, as many people could be working on the same project.
$ git config --global user
$ git config --global user.email [email protected]
Git on your system use these credentials every time you push some code to the remote repository. You can also view all Git configuration
$ git config --list
2. Set Up and Initialization :
Check your git version with following command, which will also confirm that git is installed.
$ git –version
Initialize your current working directory as a Git repo
$ git init
To copy an existing remote git repository with repo’s URL or
$ git clone https://www.github.com/username/repo-name
Show your current git directory's remote repo
$ git remote
3. Staging :
When you have modified a file(s) and have marked it to go in your next commit, it is considered to be a staged file(s).
Check status of your git repo, including
$ git status
To stage a file that you modified
$ git add filename
For example: $ git add user.swift
To stage or add all files in the current directory including files that begin with a “.”
Remove a file from staging while retaining changed within your working directory
$ git reset filename
For example: $ git reset user.swift
4. Committing :
Once you have staged your all updates, ready to commit them, and record changes you have made to the repository.
To commit staged files, run commit command with your meaningful commit message so that you can track the commits later.
$ git commit –m “Your commit message”
Condense staging all tracked files and commit in one go
$ git commit –am “Your commit message”
Modify your commit message
$ git commit –amend –m “New commit message”
[To be continued…]
Satish is working as a Mobile Application Developer. He is eager to learn about technologies and never neglect the opportunity. He believes in "Don't only dream, Work for it".