Git Cheatsheet

Β·

2 min read

Git is a distributed version control system that allows developers to collaborate on large or small projects.

To get started with git use the following commands.

Setting git username :

git config --global user.name "<git user name>"

Setting git user Email :

git config --global user.email  "<git user email>"

Initialize git repo :

git init

Adding files to staging area:

To add single file

git add <file_name>

To add all files

git add  .

Status of the repository :

To see the files in committed/uncommitted and staging area in current working directory run this command.

git status

Cloning the repository:

To get copy of existing repository.

git clone <repo-url>

Commit changes :

git commit -m <"commit message">

Commit history in Git :

git log

To remove tracked files from current directory :

git  rm <file_name>

Ignore files:

Create a .gitignore file, add the file/folder names you want to ignore from tracking, and commit it.

Creating a new branch in Git :

git branch <branch_name>

Switch branch:

git checkout <branch_name>

List the branch:

git branch

Create new branch and switch to it

git checkout -b  <branch_name>

Delete branch

git -d <branch_name>

Merge branch with current branch

git merge <branch_name>

Add a remote repository

git add remote <repoURL>

Push changes to remote repository

git push

List the remote url

git remote -v

Pull changes from remote repository

git pull

Conclusion

This is the basic and most used git command, hope this help you to understand git little bit. Thank you

Β