-
Notifications
You must be signed in to change notification settings - Fork 3
Version control with Git: a quick how to
-
Install and open a git session
-
Start a project
-
Record file changes
-
Collaborate with github
-
References
- Install git.
- Open the file explorer and go to the working directory. Right click somewhere in background of the explorer window and click
git bash
.
- Install Github for windows
- Open the Github app, click on the small gear on the top right and click
open git shell
- Open a terminal
- Install git:
apt-get install git
- That's all
- On the project's page, on the bottom right, copy the 'clone URL'. If you are at the ICM, choose 'https' beforehand. You should get somtehing like
https://github.com/MBB-team/project-name.git
- In the command window, type:
git clone https://github.com/MBB-team/project-name.git
- Voilà!
The typical workflow is:
-
Start a git session
-
Select the files you changed and want to track
-
Take a snapshot of the modifications (commit) and give a label to the snapshot
A good practice is to commit changes that are minimal and independent: prefer a lot of small meaningful commits ('typo corrections', 'cleaning file', 'that process now relies on this and that functions') to a big one collapsing all recent changes (eg. 'all changes made since two weeks ago'). Then you can revert a specific commit (eg. a functionnal change) without loosing other independant modifications (eg. typos)
- If you want to save all changes at once:
git add --all
- If you want to select only a subset of files:
git add filename1 filename2
You can use jocker (*) to select multiple files.
- Use
git status
to get a list of tracked changes.
- Just give a label to identify the set of changes (it will appear publicly on the website):
git commit -m 'a meaningful label'
Tip: Adding modifications to the last commit
Did you forget a file in your last commit and does not want to make a new lousy commit just to add it? You can append some modifications (after using git add) to the last commit (and only the last one) like this:
git commit --amend
Modify the message, then quit the editor (ctrl+c, then type :quit + enter) and you're good. However, do not do this if you have already pushed on Github !!
All commits are local: they only affect your working directory. You can however send (push) your commit online and retrive (pull) modifications made by other contributors to synchronize your work.
The typical workflow is:
-
Commit your modifications
-
Pull other's commit to be sure to have the last public version.
-
Test your code and resolve possible conflicts
-
Commit patches if necessary
-
Push your work on Github
git pull
Tip: pulling with untracked changes in your directory, (ie without having to commit first)
git stash
git pull
git stash pop
The stash
command discard (and save) all changes untracked since the last commit. The stash pop
reapply previouvsly stashed changes. Thus, the three lines above allow you to perform a pull without having to commit your changes first (but you know it's bad to do that...).
git push
To avoid warnings, use the non-ambiguous syntax git push origin master
You can check on the website if it worked!
Git cheat sheet