Rough guide to Git (and Github)

As a rule, prefix the following commands with 'git '

Text editor setup (#)

# with atom
config --global core.editor "atom --wait"


Setup

clone https://www.github.com/company/project dir
cd dir
remote add upstream https://github.com/acme/repo

Note:
  • Add upstream does not validate your input. If later you find the URL is incorrect, use git remote rm upstream to reset.
  • Use git remote -v and git status to check your setup.
Branching

Creating a remote branch first is easier. Then,

fetch -all 

...to make this branch visible locally.

Branch creation (local)

checkout -b branch_name # create a new branch
push origin branch_name # upload
branch                  # view branches

Catch up  

checkout master
fetch upstream

merge upstream/master
push # (optional)

Rebase and squash

Catch up, then:

checkout branch
rebase master -i
push -f

Undo a 'push' (unsafe!)

git reset --hard HEAD~N # hopefully, N==1
 

When you can't connect

If you get a "443 no error" message while connecting, try SSH instead of http:

git clone git@github.com:company/project.git


Cleaning

Delete a remote branch
push origin :BRANCH

Discard local changes
reset --hard

Discard untracked files:
clean -f 
...and before that clean -f -n to preview the result.

Archeology

See here for exploring older revisions.

Tags

git tag TAG # 'TAG' is the name of your build
git tag # view all tags

Push tags:

git push origin TAG

Checkout a given tag:

git checkout tags/TAG

Ridding us of all gits

find . | grep .git | xargs rm -rf

No comments:

Post a Comment