How to use GIT

This is quick tutorial on how to use capabilities of GIT tools for software development in team.

  1. To access the GIT repository:
  2. Register on the JINR GitLab site with @jinr.ru mail.
    Add SSH key in – your personal gitlab profile!

    To get zip archive without registration and SSH keys (only for read):

    MpdRoot archive
    BmnRoot archive
    SpdRoot archive
    
  3. Add your Git username and set your email
  4. It is important to configure your Git username and email address, since every Git commit will use this information to identify you as the author.

    On your shell, type the following command to add your username:

    git config --global user.name "YOUR_USERNAME"
    

    To set your email address, type the following command:

    git config --global user.email "your_email_address@example.com"
    

    To view the information that you entered, along with other global options, type:

    git config --global --list
    
  5. To get a GIT repository use this command
  6. for mpdroot:

    git clone git@git.jinr.ru:nica/mpdroot.git
    

    for bmnroot:

    git clone git@git.jinr.ru:nica/bmnroot.git
    

    for spdroot:

    git clone git@git.jinr.ru:nica/spdroot.git
    
  7. To download the latest changes in the project
  8. git pull
    
  9. To view all branches in the project
  10. git branch -r
    
  11. To work on an existing branch
  12. To switch to an existing branch, so you can work on it:

    git checkout NAME-OF-BRANCH
    
  13. To create a new branch and start working with it
  14. Please use names for branches in accordance with the task for common understanding, like: feature-new-geometry or bugfix-old-problem. Spaces won’t be recognized in the branch name, so you will need to use a hyphen or underscore.

    git checkout -b NAME-OF-BRANCH
    
  15. To add new file or folder in your branch
  16. git add NAME-OF-FILE
    
  17. To add all new files or folders in your branch
  18. git add .
    
  19. To view the changes you’ve made
  20. It’s important to be aware of what’s happening and the status of your changes. When you add, change, or delete files/folders, Git knows about it. To check the status of your changes:

    git status
    
  21. View differences
  22. To view the differences between your local, unstaged changes and the repository versions that you cloned or pulled, type:

    git diff
    
  23. To save all changes that you made in local machine GIT repository
  24. git commit -am "Some comments add here"
    
  25. To save the changes in remote server machine GIT repository (origin branch)
  26. git push origin NAME-OF-BRANCH
    
  27. If you want merge NAME-OF-BRANCH with protected dev branch create merge request on GitLab site for MpdRoot or BmnRoot. Then if your branch has passed the testing without errors, you can merge branches by clicking the button on the site.

    If something went wrong

  1. Delete all changes in the local Git repository
  2. To delete all local changes in the repository that have not been added to the staging area, and leave unstaged files/folders, type:

    git checkout .
    
  3. Unstage all changes that have been added to the staging area
  4. To undo the most recent add, but not committed, files/folders:

    git reset .