Basic git commands
Here are provided a few basic git commands.
Cloning and updating an existing git repository
To clone an existing git repository:
git clone https://github.com/nicojourdain/BUILD_CONFIG_NEMO.git
Then, to update the content of your directory (i.e. if there have been changes in the cloned git repository):
git pull
Developing in a git environment (basic)
Here we assume that there is only one branch, the master branch, e.g. if you are the only developer of a simple repository.
To add one or all files to the git version control system:
git add [file_name]
git add -A
To attribute a revision hash (ID) when you have changed a file or all the files that are followed by git:
git commit -m 'explain what has been changed here' [file_name]
git commit -m 'explain what has been changed here' --all
At this stage, the revision is saved on your local computer, but not on the remote server (e.g. GitHub, GitLab,…).
To put save your latest on the remote server:
git push
To see which files have been added to git and which ones have been modified:
git status
To ignore files in the git repository (e.g. large files, intermediate compilation files, batch outputs,…):
echo "*.nc" >> .gitignore
echo "*.o" >> .gitignore
To know what is the revision hash (ID) of previous commits on your machine, you can look at files in .git/logs or type:
git log --oneline
To retrieve a single file from a previous commit:
git checkout [revision_hash] [file_name]
To switch to a previous commit:
git checkout [revision_hash]
Then, you can go back to the master branch with:
git checkout master
Tagging specific revisions
You can tag a specific revision, which can be useful to point to the tools that have been used in a paper, or to easily switch to previous revisions (e.g. model versions):
git tag -a v3.9 -m "short description" ## to tag current revision
git tag -a v3.9 -m "short description" [revision_hash] ## to retrospectively tag a previous commit
You need to specify that you want to push these tags, it is not made by default:
git push --tags
You can delete a tag:
git tag -d v3.9
To switch to a previous tagged revision:
git checkout tags/v3.9