"Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency."
otherwise: use package manager (for example on Ubuntu)
sudo apt-get install git
associate yourself with your work:
git config --global user.name "cgroll"
git config --global user.email "email@example.com"
Files basically can be in one of the following states:
Controlled by git:
files and changes need to be added to git:
git add someFile.txt
git addadds new files or changes to staging area
using git for backup, synchronization or cooperation:
a number of git hosting platforms:
Copying an existing repository from github:
git clone https://github.com/cgroll/research_tools.git
git clone firstname.lastname@example.org:cgroll/research_tools.git
git clonethe original repository automatically gets the name
git forgets nothing:
masterbranch by default
as all merges must occur locally, possible changes on the remote need to be merged first
git pull origin master
deal with merge conflicts: edit files
file content without merge problems. <<<<<<< this is the local version of the file content. ||||||| this is the version of the common ancestor. ======= this is the version of the remote commit. >>>>>>>
commit final version of files as they were edited
git add mergeFile1.txt git add mergeFile2.csv git commit -m "merge conflicts manually resolved"
push final local version to remote repository
git push origin master
pull is shortcut for two separate steps:
git fetch: download content
git merge: join different versions
if you need to update your repo from a remote, and do not want to commit temporary modifications:
git stash git pull origin master git stash apply
git commit -m "project started"
git remote add upstream https://github.com/user/gitRepo.git
⇒ messing with history could make some commits useless
temporarily recreate old state of repo
git checkout 4d3d2fd32
recreating old state with editing enabled: create new branch at old repo state
git checkout -b testingBranch 4d3d2fd32
⇒ modifications in testingBranch can be merged back into master
delete everything up to some state in the past
git reset --hard 4d3d2fd32
If other people did build some changes on your history, you might delete some old commits that are required by their work.
⇒ Never mess with publicly available history in order to not break existing commit sequences.
if experiment fails: discard modifications by checking out the latest committed file version
git checkout filename.txt