DEV Community

muneebejazz
muneebejazz

Posted on • Edited on

Github commands Cheatsheet

//check if git is installed in the system
git --version

//set your name
git config --global user.name "John Doe"

//set your email id
git config --global user.email "example@gmil.com"

//edit the whole config file
git config --global --edit

//Initialize git repository
git init

//get the status of the files tracked by git
git status

//to track a file by git use (git add) command and then name of the file or folder to track
git add example_filename.py

// to track all the files use dot .
git add .

//to commit changes use (git commit) with -m flag for message for the commit
git commit -m "example_message"

//to see all of the commits git log command is used
git log

//to move between the commit changes use git checkout command
git checkout "hash_code_of_the_commit"

//to move the head to master
git checkout master

//to make a new branch
git branch example_branch_name

//to move to branch use checkout command
git checkout example_branch_name

//to create and move to the newly created branch use flag -b
git checkout -b branch_name

//to get the origin of the remote
git remote -v

//to set the origin of the remote repository
git remote add origin "https://github.com/example_repository

//renames the main branch to master
git branch -M master

//push the code into your repository on the github, or gitlab
git push -u origin master

//clone a repository from github, gitlab url
git clone "https://github.com/repo_url"

**

Common Github Errors

**
If you accidently include node_modules folder
then you need to remove it from the cache in order to get rid of node_modules resided in your github repo

git rm -r --cached node_modules

Top comments (0)