Git cli

From wiki.techunit.org
Jump to: navigation, search

Usage

Create a new repository on the command line

touch README.md
git init
git add README.md
#OR
git add .
git commit -m "first commit"
#SSH
git remote add origin ssh://user@git.example.com:2222/userSpace/ProjectName.git
#HTTPS
git remote add origin https://user@git.example.com:8080/userSpace/ProjectName.git
git push -u origin master

Push an existing repository from the command line

git remote add origin ssh://user@git.example.com:2222/userSpace/ProjectName.git
git push -u origin master

Clone repository

git clone ssh://user@git.example.com:2222/userSpace/ProjectName.git

List remote repositories

git remote -v

Compare commits

git diff
git status

Branches

List branches

git branch
#OR
git branch -v # Display branch and last commit

Create branch

git branch newbranch

Switch branch

git checkout newbranch

rename branch

#current branch
git branch -m newbranchname
#other branch
git branch -m <oldname> <newname>

Push new local branch

git push -u origin newbranch

Merge branches

git checkout master
git merge newbranch

Delete branches

# locally
git branch -d new_branch 
#Remotly
git push origin --delete new_data_model

Commits

useful commands

# List commits
git log

#delete commit
git reset HEAD^
	
#revert
git revert HEAD^

Sources

Useful links

Elliot
techUnit's cofounder