Plan
- Initial
- create files & folders & branches
- del files & folders & braches
- merge branches
- revert changes
Resource
ssh
type %userprofile%\.ssh\id_rsa.pub | clip
cat %userprofile%\.ssh\id_rsa.pub | clip
$ ssh -T git@github.com
$ ssh -T git@bitbucket.org
$ git remote set-url origin git@github.com:username/your-repository.git
Settings
$ git config --list
$ git config --global --edit
...
$ git config --global http.proxy $PROXY_URL
$ git config --global https.proxy $PROXY_URL
...
$ git config --global user.name "Samer Hijazi"
$ git config --global user.email "samer.hijazi@samerhijazi.net"
...
$ git config --global core.autocrlf true # Working on Windows, Linux, macOS Maschines.
$ git config --global core.autocrlf false # Working just Windows Machine.
$ git config --global core.longpaths true
...
$ git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
...
$ git config --global diff.tool bc
$ git config --global difftool.bc.path "C:/Program Files/Beyond Compare 4/bcomp.exe"
...
$ git config --global merge.tool bc
$ git config --global mergetool.bc.path "C:/Program Files/Beyond Compare 4/bcomp.exe"
...
$ git config --global alias.cp '!git commit -a -m "Update" && git push'
...
$ git commit --amend --reset-author
Credential
- default: no cache at all
- cache: keeps credentials in memory for a certain period of time.
- store: saves the credentials to a plain-text file on disk.
- Mac-Chain: in Mac caches credentials in the secure keychain "osxkeychain".
- Windows-Chain: in Windows caches credentials in the secure keychain.
git config --global credential.helper unset ...........................# remove stored password
git config --global credential.helper store ...........................# save entered password
git config --global credential.helper cache
git config --global credential.helper 'store --file ~/.my-credentials'
git config --global credential.helper manager
git config --global credential.helper wincred
git config --global --edit
...
git credential-manager version
init
git init --bare # Initial Repo for remote
git init # Initial Repo for local
...
git remote add origin https://samerhijazi@gitlab.com/samerhijazi/public.git
Life Cycle
git clone ssh://ssh-w0000000@servername.com/www/htdocs/w0000000/repository/git/projectname.git
git pull
git add README.md
git commit -m "First commit"
git push -u origin master
Branching
$ git checkout -b myfeature develop # create a new brach from develop
$ git branch -m feature1 feature2 # To rename a local Git branch
$ git push origin -u feature2:feature3 # To rename a remote Git branch
...
$ git branch -a # list all branches
$ git branch -r # list all updated branches
$ git branch -d myfeature # delete branch
...
$ git fetch # update the list of remote branches
$ git fetch --prune # remove remote branches that not longer have a counterpart.
$ git push origin --delete test # delete origin branch
$ git checkout $NAME_BRANCH_OLD
$ git branch -m $NAME_BRANCH_NEW ................ # Rename the local branch.
$ git push origin -u $NAME_BRANCH_NEW ........... # Push the local branch and reset the upstream branch.
$ git push origin --delete $NAME_BRANCH_OLD ..... # Delete the remote branch.
$ git branch -d feature/login # Delete branch local
$ git push origin --delete feature/login # Delete branch remote
Taging
$ git tag -d $(git tag -l) # Delete All local tags. (Optional Recommended)
$ git fetch # Fetch remote All tags. (Optional Recommended)
$ git push origin --delete $(git tag -l) # Delete All remote tags. Pushing once should be faster than multiple times
$ git tag -d $(git tag -l) # Delete All local tags.
Remove & Rename Files
$ git checkout $NAME_BRANCH
$ git rm -r $NAME_FILE ...................... # remove file
$ git mv $NAME_FILE_OLD $NAME_FILE_NEW ...... # rename file
$ git commit -m "My Massage"
$ git push origin $NAME_BRANCH
...
$ git clean -fd # remove directories forced
Reset
$ git stash # Save all local changes und remove them from workspace.
$ git fetch # fetch from the default remote, origin
$ git reset --hard origin/master # reset your current branch (master) to origin's master
Merge
$ git checkout master # change to branch where the merge will done
$ git merge --no-ff develop # merge develop in master
$ git push
...
$ git merge --abort # returen to the state before starting the merge.
$ git reset --hard # roll back to the commit before the merge.
Checkout
$ git pull
$ git pull --rebase origin master ............... # get changes from remote master. And commit it for local/user commit.
$ git push --force-with-lease ................... # To avoid overwrite history from rebase, Lease entsure that history dokumented.
Git branching model
########### Feature #########################
$ git checkout -b myfeature develop
...
$ git checkout develop
$ git merge --no-ff myfeature
$ git branch -d myfeature
...
$ git push origin develop
########### Release #########################
$ git checkout -b release-1.2 develop
$ git commit -a -m "Bumped version number to 1.2"
...
$ git checkout master
$ git merge --no-ff release-1.2
$ git tag -a 1.2
...
$ git checkout develop
$ git merge --no-ff release-1.2
$ git branch -d release-1.2
########### Hotfix #########################
$ git checkout -b hotfix-1.2.1 master
$ git commit -a -m "Bumped version number to 1.2.1"
...
$ git checkout master
$ git merge --no-ff hotfix-1.2.1
$ git tag -a 1.2.1
...
$ git checkout develop
$ git merge --no-ff hotfix-1.2.1
$ git branch -d hotfix-1.2.1
CICD
git --no-pager show -s --format=\'%ae\' # Disaply email address last commit
git config user.name # Dispaly email address user