My Git commandline Cheat-sheet

Creating a new repository

mkdir project

cd project

git init

git remote add origin git@github.com:yourlogin/your-repo.git

git add .

git commit -am “new repository”

git push -u origin master

Cloning existing repository

git clone https://github.com/username/your-repo.git

Creating branch

git checkout -b feature-1

# you are now in a branch, you can edit and create new files

git add .

git commit -am “new feature”

Merging branch to master

git checkout master

git merge feature-1

git push

Deleting branch

git branch -d feature-x

List all branches

git branch -a

Switch branch

git checkout feature-x

Switch to master branch

git checkout master

Listing Remote repositories

git remote -v

Replacing remote repository

# in case your remote repository changes, or you want to switch from HTTPS->SSH or SSH->HTTPS

git remote remove origin

git remote add origin git@github.com:yourlogin/your-repo.git

Leave a Reply