Codementor Events

Simple and Easy GIT process for small to large projects

Published May 18, 2021Last updated Jan 02, 2023
Simple and Easy GIT process for small to large projects

About Git

Git is distributed version-control system for tracking changes in files. Git is an example of Distributed Version Control System. That means that rather than having only one single place for the full version history of the software as is common in once-popular version control systems like CVS or Subversion (also known as SVN), in Git, every developer's working copy of the code is also a repository that can contain the full history of all changes

Clone the repository

Clone the repo to your machine.

Open a terminal and run the following git command -

git clone {repo_url}

Create a branch

Create the branch you want to work on

git checkout -b {branch_name}

This command will create a new branch from the current branch you're working on. Usually we need to create from 'master` branch.

Make necessary changes and commit those changes

Add your changed files

git add {filename}
This will add your modified files to the current branch.

Commit your added files to the git

git commit -m "desciption of changes"
This will commit your changes to the current branch.

Push to the branch you’re working on

git push origin {BRANCH_NAME}
This command will push your committed changed to the remote repo.

Before submitting your changes for review

Rebase your working branch with master branch.

git rebase --pull --autostash origin master

Note: This will save you from having merge conflict in your PR.

Now submit the pull request and get review on your pull request.

Other useful command can be used during the process

git init
It initializes Git in the folder. This command is used only once per project and this is usualy the first command you'll run in a new project.

git log
It will show all the commits history in the project.

git branch
It will show as all our local branches.

git remote add {name} {project_url}
It adds new remote url.
It takes two arguments:
a remote name eg. origin
a remote url eg. https://github.com/{username}/{repo}.git

git pull {remote_name} {branch_name}
It will copy the contents from a remote repository branch and merge all the changes into the current branch.

git reset {commit_hash}
It will go back to some commit, but it will delete all commits that were after the specified commit.

git reset --hard {commit_hash}
It will go back to some commit, but it will delete all commits that were after the specified commit and it will revert all the files as they were at the specified commit

git branch -d {branch_name}
It will delete a branch that's already merged

git branch -D {branch_name}
It will force delete a branch even if it's not already merged

Discover and read more posts from Saurabh Yadav
get started