- 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 |
Before following the below commands you would need to set Git with your GitHub profile and a SSH key.
For GitHub:
For SSH key:
-
Create a folder on your Desktop named
test
- Open
Git Bash
on your Desktop and create a foldertest
with themkdir test
command.
- Open
-
Move to the
test
folder -cd test
-
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 thels -a
command we can see the mentioned directory. -
Create
file-1.txt
in thetest
folder -touch file-1.txt
-
Check the status of your Working directory
git status
From the result, it can be seen that you don't have any commits and have 1 untracked file. -
Move the file to the Staging area
git add file-1.txt
-
Commit the changes to you Local repository
git commit -m"[MESSAGE]" git commit -m"Created file-1.txt"
When you see the above message, that means you are ready to the push the changes and add them to the Remote repository. -
Add some text to
file-1.txt
-echo "Sofia" >> file-1.txt
From the above message you can either prepare your changes for commit or discard the changes you have made.Restore the previous state of the file Keep the changes you made and prepare them for commit git restore file-1.txt
git add file-1.txt
With this command you can add 1 file at a time, but what if you have multiple...
-
Add ALL files at once to the Staging area
git add .
-
Commit the changes
git commit -m"Added 2 new files and changed file-1.txt"
-
Remove
file-3.txt
rm -i file-3.txt
-
Prepare everything for commit
git add .
-
Commit
git commit -m"Deleted file-3.txt"
-
Check the history of your commits
git log
-
Use the below command to rename the current branch to
main
git branch -M main
-
Create a repository on GitHub and connect it to your Local repository
After you have created a repository on GitHub copy the below:git remote add origin [URL] git remote add origin git@github.com:DenisBuserski/test.git
-
Push your changes:
git push -u origin main
-
Add
README.md
in your Remote repository
We don't have thisREADME.md
file in our Local repository, so let's get it.git fetch
git pull
git clone
Retrieves changes from a Remote repository without merging them into your Local repository Fetches changes from a Remote repository and automatically merges them into your current branch Creates a copy of a Remote repository on your Local machine When you want to merge the changes use git merge
git fetch
+git merge
git clone [URL]
Command | Description |
---|---|
git branch |
Show all branches |
git branch [BRANCH_NAME] |
Create branch |
git branch -m [BRANCH_NAME] |
Rename the current branch |
git branch -m [OLD_BRANCH_NAME] [NEW_BRANCH_NAME] |
Rename branch you are not on |
git branch -d [BRANCH_NAME] |
Delete branch |
git switch [BRANCH_NAME] |
Switch branch |
git checkout [BRANCH_NAME] |
Old way to switch branch |
git checkout -b [BRANCH_NAME] |
Create new branch and switch to it |
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 - Владимир Тасев
How to setup and use Git and GitHub with IntelliJ IDEA [2024] | Git | GitHub | IntelliJ
Git Explained in 100 Seconds
Git Branches Tutorial
Git & GitHub Tutorial for Beginners #8 - Branches
git with Intellij Idea