|
|

|
|
|
|
|
|
|
|
|
All git commands start with git. They must be run in a terminal (Linux, macOS) or command prompt (Windows).
|
|
|
|
|
|
### Configure Git
|
|
|
|
|
|
`git config --global user.name "UserName"`
|
|
|
|
|
|
`git config --global user.email "UserName@univ-lorraine.fr"`
|
|
|
|
|
|
> To check git version:
|
|
|
> `git --version`
|
|
|
>
|
|
|
> To check the configuration:
|
|
|
> `git config --global --list`
|
|
|
>
|
|
|
|
|
|
# Configure credentials:
|
|
|
It allows locally to save credentials which means that you give once your name and password and then not anymore.
|
|
|
|
|
|
`git config --local credential.helper store`
|
|
|
|
|
|
|
|
|
### Cloning an existing repository (master and branchs)
|
|
|
`git clone https://gitlab.com/gitlab-tests/sample-project.git`
|
|
|
|
|
|
|
|
|
|
|
|
### Updating/Getting files from the repository
|
|
|
`git pull origin master` or `git pull origin BranchName`
|
|
|
|
|
|
|
|
|
|
|
|
### Uploading files to the repository
|
|
|
`cd directory-name`
|
|
|
|
|
|
To know the status of your branch type (list all the files that have to be committed):
|
|
|
`git status`
|
|
|
|
|
|
To add new files or folders in staging area:
|
|
|
`git add FileName AnotherFileName` or `git add *`
|
|
|
|
|
|
To commits all the changes with a message:
|
|
|
`git commit -a -m "xx: message"`
|
|
|
|
|
|
`git push origin master` or `git push origin branch-name`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Revert file modification
|
|
|
|
|
|
If you have an uncommitted change (its only in your working copy) that you wish to revert (in SVN terms) to the copy in your latest commit, do the following:
|
|
|
|
|
|
`git checkout FileName`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Reset file modification
|
|
|
|
|
|
Undo a git add or remove files staged for a git commit
|
|
|
|
|
|
`git reset FileName`
|
|
|
|
|
|
Will remove a file named filename.txt from the current index, the "about to be committed" area, without changing anything else.
|
|
|
|
|
|
To undo git add . use :
|
|
|
|
|
|
`git reset`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Branches
|
|
|
Branches are used to develop features isolated from each other, you create a new one to separately test something. The master is the default branch when you create a repository. Use other branches to develop and merge them into the master branch after conclusion.
|
|
|
In order to have access to the files in a branch, you must move into this branch.
|
|
|
|
|
|
To creat a new branch:
|
|
|
`git branch BranchName`
|
|
|
|
|
|
To move inside a branch:
|
|
|
`git checkout BranchName`
|
|
|
|
|
|
To delete a branch:
|
|
|
`git branch -d BranchName`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Git Large File Storage (LFS)
|
|
|
Configure Git LFS to track the file:
|
|
|
|
|
|
`git lfs track FileName`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Merging files
|
|
|
|
|
|
#### Merge request
|
|
|
|
|
|
If you want your branch to be merge to the master branch contact:
|
|
|
|
|
|
- [Adrien Baldit](/baldit1/bio2mslib/-/wikis/adrien.baldit@univ-lorraine.fr)
|
|
|
- [Cedric Laurent](/baldit1/bio2mslib/-/wikis/cedric.laurent@univ-lorraine.fr)
|
|
|
|
|
|
#### Update a Branch to Master
|
|
|
|
|
|
First commit and push all your modified files with:
|
|
|
|
|
|
```
|
|
|
git commit -a -m "xx: update"
|
|
|
git push
|
|
|
```
|
|
|
|
|
|
For practical reason delete your `config.py` that you will reedit later.
|
|
|
|
|
|
Go to the branch you want to update with the master:
|
|
|
`git checkout lem3xx`
|
|
|
|
|
|
Then merge:
|
|
|
`git merge origin/master`
|
|
|
|
|
|
Exit gnu nano:
|
|
|
ctrl+X
|
|
|
|
|
|
Then push:
|
|
|
`git push origin lem3xx`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Summarizing
|
|
|
<img src="https://www.edureka.co/blog/wp-content/uploads/2016/11/Git-Architechture-Git-Tutorial-Edureka-2.png" width="400">
|
|
|
|
|
|
Source: [Git Tutorial](https://www.edureka.co/blog/git-tutorial/) written by [Reshma Ahmed]
|
|
|
|
|
|
|
|
|
### Sources:
|
|
|
[https://livecodestream.dev/post/git-concepts-and-workflow-for-beginners/](https://livecodestream.dev/post/git-concepts-and-workflow-for-beginners/)
|
|
|
|
|
|
[https://dzone.com/articles/top-20-git-commands-with-examples](https://dzone.com/articles/top-20-git-commands-with-examples)
|
|
|
|
|
|
[https://rubygarage.org/blog/most-basic-git-commands-with-examples](https://rubygarage.org/blog/most-basic-git-commands-with-examples)
|
|
|
|
|
|
[https://www.edureka.co/blog/git-tutorial/](https://www.edureka.co/blog/git-tutorial/) |
|
|
\ No newline at end of file |