This is moved to <../notes/git-notes> Setup variables:
git config --global user.name "Phyrum Tea"
git config --global user.email phyrum@tea.ch
Verify variables
git config --list --global
Create a remote bare repo. This can be on an USB stick like D:\git
cd /Users/ptea
mkdir git
git init --bare --shared wisecards.git
Convert current project to git project
cd wisecards
vi .gitignore // to ignore bin/ and gen/ folders.
git init
git add .
git commit -m ‘Initial commit’
to remove or delete multiple files
git add -u
add content to the remote bare repo
git remote add origin /Users/ptea/git/wisecards.git
git push -u origin master
after editing some files
git add .
git commit -m 'added new benchmarks'
git push
shortcut for add and commit.
git commit -a -m 'added new benchmarks'
git push
If I have some changes that I want to add to the last commit. --force
is only needed when the last commit was already pushed to the remote repo.
git commit --amend --no-edit
git push --force
Start new branch alpha15
git branch alpha15
git checkout alpha15
Shorthand for new branch and checkout
git checkout -b develop
Make branch alpha15 public
git push origin alpha15
Continue work on master
git checkout master
git tag 1.5.0.3a
replace tag git tag -f 1.5.0.3a
git push origin -f 1.5.0.3a
git push origin 1.5.0.3a
a. initial on the other mac with access to network drive.
git clone file:///Volumes/ptea/git/wisecards.git
b. updates after clone
cd wisecards
git pull
git checkout alpha15
move master to develop
git checkout master
git merge develop
git checkout alpha15
git merge master
publish the 2 merges
git push origin master
git push origin alpha15
Delete unused branch, branches which are merged in master:
# list merged branches for cleanup/delete
git branch --merged master
# delete branch, multiple branches can be listed after -d flag
git branch -d alpha15
git push origin :alpha15
Show origin url
git remote -v
Change origin
git remote set-url origin file:///C:/Users/ptea/git/WiseCrards.git
file:///X:/pht/Git/bbtcare.git
show history
git log --pretty=oneline
Made a mistake and want to revert commits to the origin/master?
git reset --hard origin/master
Rebase
I don't like using rebase
but if the project's policy requires it to fake the repo-history:
git checkout master
git pull
git checkout alpha15
# git branch --set-upstream-to origin/alpha15
git rebase master
git push --force
rebase
and squash last 2 commits
git rebase --interactive HEAD~2
Commit in wrong Branch
Sometimes mistakes happen. You checkout out a branch and made changes and commit without making a new branch. Here are the commands to undo and start a new branch:
git reset HEAD~1
git checkout -b alpha15
Using git over ssh
git clone ssh://phyrum@tea.ch:/media/Samba/Git/Test.git samba