Git: Difference between revisions
No edit summary |
(.) |
||
Line 147: | Line 147: | ||
If we each write to master -- lots of conflicts? | If we each write to master -- lots of conflicts? | ||
Contrast with creating branch for each person ?! | Contrast with creating branch for each person ?! | ||
== Recipes == | |||
=== Pusing a folder to git.xpub.nl === | |||
==== Step 1: SSH to the server and run the bash script "newrepos.sh" ==== | |||
ssh USERNAME@git.xpub.nl | |||
cd /var/www/git.xpub.nl | |||
./newrepos.sh NAMEOFREPO "Description of my great project" | |||
This spits out a message like: | |||
ALL GOOD! | |||
push URL: git.xpub.nl:/var/www/git.xpub.nl/repos/NAMEOFREGO.git | |||
You can logout now. | |||
==== Step 2: Turn your folder into a git repository ==== | |||
You can skip this step, if your folder is already a git repo. | |||
cd path/to/yourfolder | |||
git init | |||
And then add things with | |||
git add myproject.py | |||
git add somefolder | |||
Then commit them | |||
git commit -m "First commit" | |||
=== Step 3: Add the repo as a "remote" to your repo === | |||
cd path/to/yourfolder | |||
git remote add pzi USERNAME@git.xpub.nl:/var/www/git.xpub.nl/repos/NAMEOFREPO.git | |||
Note that you should add your USERNAME for ssh'ing to git.xpub.nl | |||
Now finally you can push and "set the upstream" to that remote as the default... | |||
git push -u pzi master |
Revision as of 08:48, 17 October 2018
http://eagain.net/articles/git-for-computer-scientists/
Trees, Branches, and Blobs
git init git add * git commit -m 'hello git'
init, clone
git init
git clone git://...
status, add, diff
tracked/untracked "staged"
file status lifecycle, p. 20 gitbok
git status
Add a file called ".gitignore" to ignore "temporary" or other files you don't want to track.
*.[oa] *~ *.pyc
git diff
Shows changes to unstaged files only
git diff --cached
Show what you've staged so far
commit
git commit -m 'added new quote'
git commit -a -m 'edited links'
Stages every file (that's being tracked) -- ie "auto add"
git commit --amend
Add forgotten changes to last commit.
rm
git rm readme.txt
git rm --cached readme.txt
Remove from the stage, but not the file! (untrack)
git mv
(technically git "sees" these movements already, same as mv, remove, add: but the command is there for convenience)
log
git log
git log -p -2
git log --stat
git log --pretty=oneline
git log --graph
remote
git remote
git remote -v
git add remote remote-name URL
Where remote-name is whatever you want it to be called, and the URL is a remote git URL.
git remote show origin
git fetch remote-name
pull
pull = fetch + merge
push
git push [remote-name] [branch-name]
git push origin master
tags
Show SMW ?!
<!?> Find/link workflow article for git + web
Auto-Completion
contrib/completion/git-completion.bash
Add to .bashrc:
source ~/.git-completion.bash
(or)
cp git-completion.bash /etc/bash_completion.d/
(linux)
cp git-completion.bash /opt/local/etc/bash_completion.d/
(mac)
branch
git checkout -b iss53
create + checkout a branch, short for:
git branch iss53 git checkout iss53
git checkout master
git checkout -b fix git commit -a -m 'fixed something'
git checkout master git merge fix git branch -d fix
"Fast-forward" reflects that the changes were "upstream" of the current working state.
conflict
Generally, you want to commit all your changes before switching branches (checkout)
If we each write to master -- lots of conflicts?
Contrast with creating branch for each person ?!
Recipes
Pusing a folder to git.xpub.nl
Step 1: SSH to the server and run the bash script "newrepos.sh"
ssh USERNAME@git.xpub.nl cd /var/www/git.xpub.nl ./newrepos.sh NAMEOFREPO "Description of my great project"
This spits out a message like:
ALL GOOD! push URL: git.xpub.nl:/var/www/git.xpub.nl/repos/NAMEOFREGO.git
You can logout now.
Step 2: Turn your folder into a git repository
You can skip this step, if your folder is already a git repo.
cd path/to/yourfolder git init
And then add things with
git add myproject.py git add somefolder
Then commit them
git commit -m "First commit"
Step 3: Add the repo as a "remote" to your repo
cd path/to/yourfolder git remote add pzi USERNAME@git.xpub.nl:/var/www/git.xpub.nl/repos/NAMEOFREPO.git
Note that you should add your USERNAME for ssh'ing to git.xpub.nl
Now finally you can push and "set the upstream" to that remote as the default...
git push -u pzi master