Install Git and try basic commands & workflows

I am a full stack developer mainly using golang. I work on Cloud at HPE, Bangalore, India.
Search for a command to run...

I am a full stack developer mainly using golang. I work on Cloud at HPE, Bangalore, India.
I don't understand why people still using command line to use git. Using a Git GUI client, isn't more easy?
A lot of people including me prefer CLI over GUI.
Make you feel like a hacker.
This series will teach basics of git and how to start contributing to projects by making pull requests etc. git is a version management tool which helps us store code in repos.
Both git merge and git rebase are used to integrate the changes from one branch into the other branch. We usually create a feature branch - make the code changes in form of commits and then either merge or rebase it into master. See the below image w...
What is gRPC? gRPC is a modern open source high performance RPC framework that can run in any environment. It can efficiently connect services in and across data centers with pluggable support for load balancing, tracing, health checking and authenti...
Let's assume we have a sample Golang application (in a Go project folder). Contents of main.go package main import "fmt" func main() { fmt.Println("hello world") } In the same folder, run the following commands to initialize go modules # initial...

When you create a new Kubernetes Cluster in EKS - you still need to do several things until you can start using it. This simple set of steps aims to help people create an EKS cluster in simple steps and configure the most essential services like Log ...

To implement a stack in golang we can make use of the slice datatype which golang provides which allows us to modify the size on the fly. If we were doing it in C, we would need to define a max size for the array. Lets start with a simple structure ...

The purpose of this guide is to make a simple telegram bot, which replies with a compliment for each and every message that it receives. Create a bot in telegram Look for a bot named BotFather https://t.me/botfather . This bot is used to create bots...

On this page
Its very simple to install git on any platform -
Install git on Ubuntu, or RHEL based distros
sudo apt-get install git # ubuntu based distro
sudo dnf install git # fedora
sudo yum install git # centos or rhel
If you have homebrew installed -
brew install git
For windows, we have git-scm
Download and install it HERE
git configThis is used when we try to synchronize the files between local and remote. Also all the commits have information about the person who committed.
git config --global user.name "Mridul Ganga"
git config --global user.email "[email protected]"
After this we are ready to use git to do any kind of operation.
To make a repo, we first need to create a folder ex - project1
mkdir project1
cd project1
Now that we are inside the project folder, we can initialize a git repo here.
git init
That's all we need to do to create a local repo. One thing to note is - currently this repo is not linked to any remote. Whatever changes we do - commits, branches etc will always remain on the machine and will not be synchronized with any remote repo.
Login to github and find the + button on the top right corner. Then select New repository

Follow the steps on the screen - give a name, some description and continue. This will create a new repo on github (remote repo).
Git provides a simple command to copy the remote repo to a local repo. We use the clone command for this
git clone https://github.com/mridulganga/mg-bot
cd mg-bot
Now we have a local repo which is connected to a remote, let's make changes and push those changes to the remote repo.
Use the steps above to create a github repo
use the git clone command to clone the repo
git clone https://github.com/mridulganga/repo-name
cd repo-name
# we are creating a readme file with Hello world in it
echo "Hello World" > Readme.md
git status
git diff
git add . # or git add Readme.md
git status # see status again to see staged files in green
git commit -m "adding a readme file"
Now the changes are commit to the local repo, we need to sync there changes to the remote
git push origin master
After this, goto github and you should be able to see the Readme.md file in the repo page.
Let's assume there are multiple people working on the code. Someone made some changes and pushed the code to remote. Now we want those changes in our local repo. For this we use the git pull command.
git pull origin master
# or
git pull
The above workflow can be used for personal projects or projects with few contributors. In case of open source or big projects there are usually many people working on the same repository. They make use of github issues to decide who will work on what. And the respective developers make the changes in their own feature branches. When their changes are done, they create a Pull Request. The code changes in pull request are reviewed by one or more reviewers and they give their approvals or request changes. The developer can then make changes based on review comments and keep pushing to the same branch. When the PR is in a good state, it gets merged by one of the repo maintainers. This is how the code changes land in the master branch.
Taking example of a repo https://github.com/mridulganga/mg-bot, we want to add some changes in Readme file.
git clone https://github.com/mridulganga/mg-bot
git checkout -b readme-changes
nano README.md
# add some changes in the file
I made the following change (image below)

git add README.md
git commit -m"adding insult command info"
git push origin readme-changes
when we open it on github.com we now see the following option to create a pull request from the new branch we pushed to -

You get the following page on github to create a new pull request. Give it some name and description and create the request.

Whenever we make a pull request, other people working on the code can come and review the code changes. They can put comments and suggestions on the code and then give their approvals. Below is how a typical code review page looks like

When the code reviews are done and your PR has enough approvals (usually 2) then it can be merged by a maintainer. They see something like below -
We usually get options like squash, rebase and merge commit.
The above is the workflow you can take up when you are a collaborator in any project on github. In case you want to make contributions to repo which you do not own -