GIT bash cheatsheet

  • Create repository from existing folder in github

    – open terminal and navigate to project’s folder
    – initialize repository with git init

[bash]git init[/bash]

– (optionally) create `.gitignore` file and add all files and folders that should not be a part of the repository commit like: log folders, cache folders, .project, and perhaps .gitignore itself.

add all files and folders

[bash]git add .[/bash]

commit all files

[bash]git commit -m”My first commit”[/bash]

create new repository by logging into your github account and visiting http://github.com/new

– copy remote repository url

link local repository to the remote one

[bash]git remote add origin remote repository URL[/bash]

push new repository to the server

git push -u <origin> <branch-name>

-u specifies upstream

  • Clone existing repository

git clone myGitName@http://my.repository.com

– or clone specific branch

git clone -b branchname myGitName@http://my.repository.com

  • Show

all branches and their origin upstreams

git branch -avv

– a shows all branches (current branch is marked with * in front of the name
– v verbose

remote repository path

git remote show <origin>

remote repositories list

git ls-remote

  • Branches and day to day workflow

– create new branch

git checkout -b <new_branch_name>

– delete branch

locally:

git branch -D <branch_name>

on the remote server

git push --delete <origin-server> <branch-name>

– push new branch to remote repository

git push -u origin new_branch_name

– u upstream

– reset local repository to be the same like remote repository

git reset --hard head

 

 

 

Leave a Reply