Basic Git Commands

Jigyasa
2 min readJun 1, 2021

Git is a Version Controlled System(VCS) which enables engineers to maintain and collaborate on their code.

To know git version:

git --version

Let us assume that user has access to git Repository ( SSH key got added in server).

To clone repository to your local folder:

git clone <repository.git>

Now we have cloned repo, and it’s pointing to master. I need to work on current release branch release2021

To checkout branch:

git checkout release2021

To list all branches :

git branch

Now I made some changes to this branch in my local, I need to push local changes to the server.

Step 1: Add files which have changes. Second command provided below is to add all files in one shot which got changed.

git add <file name>
git add .

Step 2: Commit added changes:

git commit -m <commit message>

Step 3: Push these changes to remote git repository from your local. Then everyone will be able to see changes we made.

git push

Before we complete above steps, some one from our team has pushed their changes. Then whenever we try to push we will get an error because our local branch is not in synchronization with remote branch changes which our colleagues have pushed .

error: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.

To resolve above error, first we need to get remote repository changes to our local repository by pulling latest code.

git pull --rebase

After above step we can run git push command.

--

--