Skip to content

DenisBuserski/Git

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to use Git

Overview

  • Software Configuration Management(SCM) = Version Control(VS/VCS)
  • Software principle
  • When several programmers write code, the codes of which are then combined into 1 project. VC allows this to be more balanced and controls the whole process
  • Keeps history of the made changes
  • Conflict - When 2 people work on the same code and correct the same line
  • Repository
    • The code repository used in a project
    • Project code
  • Open source code - Everyone can see the code
  • GitHub - If you are not added as a collaborator, you cannot make pull requests
Git GitHub Git Bash
Version control; Methodology Portal Client we use to upload code to GitHub

There are 2 types of Source-Control Systems

Distributed Source-Control System Centralized Source-Control System
Git SVN
2 types of repository
Remote - The main project from which the files are downloaded Only 1 repository (Remote repository)
Local - Everyone involved in this project has 2 repositories No Local repository
In case of conflict, the individual programmer can download the changes in his repository that the other has made and make the appropriate changes Almost always we get conflicts and they are very hard to fix

Simple Git commands


Before following the below commands you would need to set Git with your GitHub profile and a SSH key.
For GitHub:

For SSH key:


  1. Create a folder on your Desktop named test
    Open Git Bash on your Desktop and create a folder test with the mkdir test command.

  2. Move to the test folder

    cd test
    

    step_2

  3. In the Git console write the command

    git init
    

    This command initializes a new, empty repository. Git creates a new .git directory in your project. Using the ls -a command we can see the mentioned directory. step_3

  4. Use the clear command to clear the console

  5. Create file-1.txt in the test folder

    touch file-1.txt
    

    step_5

  6. Check the status of your Working directory

    git status
    

    step_6 From the result, it can be seen that you don't have any commits and have 1 untracked file.

  7. Move the file to the Staging area

    git add file-1.txt
    
  8. Check the status step_8

  9. Commit the changes to you Local repository

    git commit -m"[Message]"
    
    git commit -m"Created file-1.txt"
    

    step_9

  10. Check the status step_10 When you see the above message, that means you are ready to the push the changes and add them to the Remote repository.

  11. Add some text to file-1.txt

    echo "Sofia" >> file-1.txt
    
  12. Check the status step_12 From the above message you can either prepare your changes for commit or discard the changes you have made. If you want to restore the previous state of the file you have to use:

    git restore file-1.txt
    

    If you want to keep the changes you made and prepare them for commit you have to use:

    git add file-1.txt
    

    With this command you can add 1 file at a time, but what if you have multiple...

  13. Add 2 more files to the test folder

    touch file-2.txt
    touch file-3.txt
    
  14. Check the status

    git status
    

    step_14

  15. Add all files at once

    git add .
    

    step_15

  16. Check the status step_16

  17. Commit the changes

    git commit -m"Added 2 new files and changed file-1.txt"
    
  18. Check the status step_18

  19. Remove file-3.txt

    rm -i file-3.txt
    

    Since you are using -i, you will be asked whether you want this file to be deleted. step_19

  20. Check the status step_20

  21. Prepare everything for commit and check the status

    git add .
    git status
    

    step_21

  22. Commit

    git commit -m"Deleted file-3.txt"
    

    step_22

  23. Check the history of your commits

    git log
    

    step_23

  24. Use the below command to rename the current branch to main

    git branch -M main
    

    step_24

  25. Create a repository on GitHub and connect it to your Local repository
    After you have created a repository on GitHub copy the below: step_25

    git remote add origin [URL]
    
    git remote add origin git@github.com:DenisBuserski/test.git
    
  26. Push your changes:

    git push -u origin main
    

    step_26 We can see the files in GitHub now. step_26(1)

  27. Add README.md in your Remote repository step_27 We don't have this README.md file in our Local repository, so let's get it.

    git fetch
    
    git merge
    
    git pull
    
    git merge
    
    git clone
    

You can check here a graphical explanation of some of the commands we used.

0

Additional information


Git and Github Essentials
Git and GitHub Tutorial For Beginners | Full Course [2021] [NEW]
Git Tutorial for Beginners: Learn Git in 1 Hour
Fundamentals with C#, Java, JS & Python Jan 21 - Git and GitHub - Kiril Kirilov
GitHub: The Right Way - Владимир Тасев

About

Simple documentation on how to use Git

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published