Go Back

Git Commands


Create a repository

git init 

Check status

git status 

Add a file

git add <file name> or git add * 

After staging, to commit

git commit -m <add comments> 

Pushing the changes to remote repository

git remote add origin "<URL to the repository>" 

Push the files

git push origin <name of the branch> 

Clone the repository

git clone <URL> 

Pull the repository

git pull origin master 

To create new branch from an existing branch

git branch <name of the new branch>

To delete a branch

git branch -D <name of the branch to be deleted> 

Switch btw branches

git checkout <name of the branch> 

Checking the logs or history of the repository (logs of that particular branch)

git log 

To stash your staged files without committing

git stash 

To stash untracked files

git stash -u 

Once you are back and want to retrieve working

git stash pop 

Reverting a commit

git revert <commit id> 

Checking the differences between two versions of a file

git commit <commit id of a> <commit id of b>

Merging 2 branches

git merge <branch-name> --no-commit --squash 

Configuring git credentials

git config --global user.email <email> && git config --global user.name <userid>