Tuesday, March 3, 2015

git commands

To set up a new git repo with existing project:
cd .../project
edit .gitignore
git init
git add . -v
git commit

Add repo to bitbucket:
Create repository here: https://bitbucket.org/repo/create
git remote add origin https://user@bitbucket.org/user/project.git
git push -u origin --all
git push -u origin --tags

important concepts in git: the working tree (files on disk), the index (the staging area for the next commit), and HEAD (last commit you made)

to add new file to index OR to get a changed file to the index:
git add whatever.tex
(this does not commit the new file)
to add all changes and new files (but not rm anything) (-v for verbose):
git add -v .

to commit (will prompt for commit message):
git commit

push to github/bitbucket:
git push origin master
to push all branches/tags:
git push --all
git push --tags

diff between working copy and index:
git diff
diff between index and HEAD:
git diff --cached
diff between local (HEAD?) and github:
git diff origin/master master

status:
git status
abbreviated status:
git diff --name-status
git diff --cached --name-status

create new branch:
git checkout -b branch_name
list branches:
git branch
switch branches
git checkout branch_name

temporarily go back to older state:
git checkout [commit_hash]
...do some stuff...
(can make a new branch here with:
git checkout -b branch_name
)
to switch back:
git checkout master [or whatever original_branch was]


Make a new copy on different computer:
git clone https://github.com/user/project

simple git guide here: http://rogerdudler.github.io/git-guide/

if you get error like:
error: The requested URL returned error: 403 Forbidden while accessing https://github.com/user/project.git/info/refs
run:
git remote set-url origin https://user@github.com/user/project.git
(see http://stackoverflow.com/questions/7438313/pushing-to-git-returning-error-code-403-fatal-http-request-failed )

No comments:

Post a Comment