Sample project for the git lesson of embl software carpentry course
- The official git webpage and documentation is in this link
- Create the repo in GitHub and clone to a local directory
- To check the repo settings:
git config -l
- To set user email and preferences
git config --global user.email [email protected]
git config --global user.name "Irene de Teresa"
git config --global core.editor nano
- Add, commit:
git add filename
git commit -m "the message"
or, to not have restrictions to message length:
git commit
The basic process is file -> add (which brings to a 'stage') -> commit (adds the version to .git) .git is the directory where the repo will be developed so do not modify
- To see the history of versons and commits
git log #or
git log --oneline
- diff is a tool that shows changes between versions and repository copies:
git diff
in stage:
git diff --staged
or between two versions in the local repo:
git diff b856f26 b1f794b
to check changes since some version to the current one:
git diff 9bdd448
to color the changes:
git diff --color-words 9bdd448
- To undo commits!:
git checkout -- README.md
-
To go back in time:
First, you have to be in a clean state (commit all changes)
And then go to the desired working copy, e.g. b856f26:
git checkout b856f26
Now the HEAD will be in that point in time
- Now one can do a branch
git checkout -b one_sample_branch
- To push to a remote repository in GitHub:
git push
- To pull changes from remote repo
git pull
- If the other person has already commited changes to the remote repo, you have to first pull those changes and then push:
git pull
# Add a message to explain why you will pull
git push
- When both change the same piece of the repository, the merging can't be done automatically. In the corresponding file one sees the <<<<<<< >>>>>>> symbols and tokens related to the different versions. So one has to edit manually and decide what to chose:
nano conflicting_file_name
then delete weird symbols and choose...
git add ...
git commit ...
git push
- To protect the repository from potential changes by collaborators: in github -> settings -> branches ...
- new branch
git checkout -b whateverbranchname
- Create a repo locally:
mkdir repo_directory
cd repo_directory
git init
- Then create the corresponding repo in GitHub (e.g. at https://github.com/username/new-repo) and then link them together:
git remote add origin https://github.com/username/new-repo
git pull https://github.com/username/new-repo
git push https://github.com/username/new-repo
- For bullets, use a small '-'
- Create bold text use '**'
- Create emphasized text use '*'
- Code formatting with backticks
- For links one uses 'link name'
- The commit message should be descriptive