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 situations then this post is only for you. This will help you to give you a workable understanding.

 

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?

 

The answer is very simple, Git allows teams to effectively and efficiently contribute code to the same project in an asynchronous way. This empowers teams to collaborate better and thus allow them to solve bigger and more complex problems.

 

Question: What does Git do?

Git tool does two main things:

  1. Track the history of your files.
  2. Share and collaborate on files.

 

Question: What is the operation provided by git?

Some basic operations in Git are:

  1. Initialize
  2. Add
  3. Commit
  4. Pull
  5. Push

Some advanced Git operations are:

  1. Branching
  2. Merging
  3. Rebasing

 

 

 

The Architecture of Git :

 

Fig.1 : The Architecture of Git

Let's start...

[Note: Assumes that you have downloaded and installed git on your system]

 

Fig.2 : Git Basic Rule before you use

 

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.name "Your name"

$ 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 server location

$ 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 both, staged and non-staged files.

$ 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 “.”

$ git add.

 

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”

 

Reference: 

1. https://www.github.com

2. https://www.edureka.co/blog/git-tutorial/

3. https://cdn-images-1.medium.com/max/800/1*dZeIODNyQ9o6IfFLaTxksg.png

 

[To be continued…]

 

 

 

 

About Author

Author Image
Satish Thakur

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".

Request for Proposal

Name is required

Comment is required

Sending message..