Git Command Cheat Sheet

List all git configuration, to quit press q

> git config -l

Change name and password globally

> git config --global user.name "Daniel Leonardo Niko"
> git config --global user.email "my@email.com"

Make new repository in GitHub (case of existing local project, ex: new project from Spring Initializr)

  • Click “+” icon and select New repository
  • Input repository name, description, Public / Private
  • skip README, gitignore and license
  • Click “Create repository”
  • Go to command prompt and execute the following
> cd existing_project
> git init
> git add .
> git commit -m "First commit"
> git remote add origin https://github.com/your_username/repository_name.git
> git push origin master

Clone repository to local directory

> git clone https://github.com/your_username/repository_name.git

Clone specific branch

> git clone -b <branchname> https://github.com/your_username/repository_name.git

Checkout / switch to remote branch. For example, remote branch created by another developer and we want to pull that branch.

# fetch all remote branches
> git fetch origin
# list all branches available for checkout
> git branch -a
# pull changes from a remote branch
> git checkout -b <branch_name> origin/<branch_name>
# verify branches has been changed
> git branch

Save username and password of Git

# run
> git config --global credential.helper store
# provide username and password below
> git pull

Leave a comment