The Ultimate Guide to master git

What is Git?

SOURCE-GOOGLE

Git is the most commonly used version control system. In common terms git keeps track of changes you have done to the file and it can be reverted anytime. To understand in a better way consider, a Library book that keeps track of borrowed and returned books by a person. In a similar way, git keeps track of what, who and when was something done to the code.

Installing git,

Git can be installed on Linux, macOS, and Windows operating systems.

Note: Follow the steps provided for installation in the respective OS.

Now let’s understand default options README, .gitignore, LICENSE. which are available.

A README is a place to share instructions and rules about the repo. It also tells people why your project is useful. A README file is often the first item a visitor will see when visiting your repo. While the .gitignore file lives in the root of your project folder and contains rules for the rest of the files that must be ignored. A file needs to be licensed only if it’s truly open source and other people need to add and change your code and are free to use it. Usually, people place their license text inLICENSE.md

Initialising git to your repo,

Traverse to the working directory and you can type git init to simply initialize git to the current working directory.

git init
git add README.md
git commit -m "Commit Message"
git remote add origin https://github.com/username/reopname.git
git push -u origin master

Once the changes are done to the code it needs to be saved, hence we commit the changes with a good commit message where other developers can understand. Here is a list of good commit messages

feat - a new feature
fix - a bug fix
docs - changes in documentation
style - everything related to styling
refactor - code changes that neither fixes a bug or adds a feature
test - everything related to testing
chore - updating build tasks, package manager configs

Creating a branch and working with dev teams,

A branch is a separate workspace for you to experiment and make the code changes without affecting the master branch. The branch can be helpful when a new feature or bug fix is left incomplete, but the changes need to be stored without merging with the master and corrupting master branch code.

Before creating a branch, the latest changes from the master needs to be pulled with the help of,

$ git pull

You can then create a branch on your local machine and switch to the branch,

$ git checkout -b [name_of_your_new_branch]

The new changes can be incorporated into the new branch and later on, it can be pushed with the help of the following command,

$ git push origin [name_of_your_new_branch]
Example: $ git push origin bugFix

A pull request can be opened later on once the changes are pushed so as others in the dev group can review the code changes and get a heads up to merge it with the master branch.

Note: Latest changes from the master branch should be pulled to be in sync with the master branch or it can lead to branch conflicts.

Wrapping it up,

Git can be used to maintain track of code changes and it’s the most commonly used version control system and easy to use. Developers working in teams use VCS for easier work distribution.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store