Skip to content
ferng edited this page Mar 21, 2018 · 44 revisions

Thank goodness Linus came up with Git, cvs, was alright, SVN was definitely top heavy, merging branches, eurgh. Now, don't get me wrong you can cock up with Git, but it's also very easy to fix it when you do.

Config

General config

git config --global alias.lg "log --color --graph --pretty=format:'%C(yellow)%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

#common
git config --global user.name "ferng001"
git config --global user.email ferng001@gmail.com
git config --global core.autocrlf input
git config --global credential.helper cache
git config --global push.default simple

#set up proxy
export http_proxy=fernandog:myPassword@10.1.10.15:8080
export https_proxy=fernandog:myPassword@10.1.10.15:8080

#ignore line feed crap
git config core.filemode false

Key Generation

#linux
cd ~/
mkdir .ssh
ls -al .ssh
ssh-keygen -t rsa -C "ferng001@gmail.com"
#check ssh-agent is running
eval "$(ssh-agent -s)"
#add ssh key to agent
ssh-add ~/.ssh/id_rsa
#copy to clipboard to add to repository
clip < ~/.ssh/id_rsa.pub

#windows
#configuration and key generation - windows
#use puttygen to pull out public key (prom privatekeys)

Alternative configuration through proxy with putty

New Putty Session

Parameter Value
Session Name zzzproxy
Host Name bitbucket.org
Port 22
Putty Proxy Configuration
Type HTTP
Host hjs1-proxy-01
Port 3128
Proxy command connect %host %port\n

Configure Cygwin

# at home directory
vi .profile
GIT_SSH=/cygdrive/c/Program\ Files\ \(x86\)/PuTTY/plink.exe
export GIT_SSH

git through the proxy

git clone git@zzzproxy:ferng001/monipoop.git

Usage

Pull down changes from remote into local

git log  --show all history
git fetch origin
git merge origin/master

Change review

#review what's changed etc
git status
#tidy stuff if necessary and when your're happy this will add / update / delete files as necessary
gitCom.sh "this is my comment"

#review project history
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
#or if alias has been setup
git lg
#and to list the changes
git lg -p

Branches

#throw away local changes
git checkout -f 

#merge remote changes into my local copy
git pull origin <branch>

#delete remote branch
git push origin --delete core-project

#delete local branch
git branch -D branch

Commits

#tag a version
git tag -l 'v1.4.2.*'

#differences between current and last commit
git diff

#differences between last commit and repository
git diff origin/master

#reset working tree to the last commit / clean up any left over files
git reset --hard HEAD
#what is going to be cleaned up
git clean -n
#clean it up
git clean -f

#reset working head to remote
git fetch origin
git reset --hard origin/master

Pull requests

  • Fork project into my repo
  • Create branch for change
git fetch origin
git checkout -b new_branch origin/new_branch
  • Make changes
git pull --rebase main master     # update with other changes from their repo
git rebase --continue             # if you need to fix any conflicts
git merge master
git checkout master
git merge --no-ff new_branch
git push origin master
  • Create pull request comparing my branch with their branch

Clone this wiki locally