Basic git commands.

Akhila
2 min readJan 12, 2021

Everyday git commands for developers.

***********************

This document mainly focus on basic everyday git commands for the newbie.

  1. Cloning a new repository.

git clone “repository”

repository: Copy the link from your bitbucket/gitlab project.

2. Check current branch.

git branch

This will show you the current branch you are in your local.

3. Creating a new branch.

git checkout -b <branch_name>

branch_name: Branch name can be anything.

Sugessted : [feature/bug/improvement/] / [ticket-number]- [ticket-description]

Eg: feature/CPT-1-create-a-new-page-with-image

4. Pulling from a remote branch to local branch.

git pull origin <branch-name>

5. Adding files to git.

Adding all the files

git add .

To add single file we use

git add <file_name>

6. Commit files.

Using a message to create commit for the added files.

git commit -m “message”

This command is used after adding the files.

7. Rebasing files.

Inorder to update your branch with the latest remote branch without breaking the pipeline, we use rebase

git rebase -m <branch_name>

This takes to a editor to see your commits, be carefull saving this file, use ctrl+X then ctrl+Y .

to rename your message use.

git rebase -i <branch_name>

ctrl+X then ctrl+Y

8. Pushing local branch changes to remote branch (considering 2 branches are different).

git push origin <local_branch>:<remote_branch>

9.See the status of the git.

git status

10. Storing current working branch changes.

git stash

This will store your current branch changes and gives a clean working directory

11. Retriving last stored changes.

git stash pop

This command retrive all the changes stored when stashed.

12. See your work.

git log

This shows the logs i.e., your work done on git.

--

--