Git is a free and Open Sourced Version Control System, ie, allows programmers to keep track of any changes with files involving collaborative software development.
// I will be using VS Code for these examples.//
Before you can use Git in VS Code, you first need to clone a repository. Open Github and the repository that you want to clone, fork the repository. Once the forked Repository opens, copy the URL. Open VS Code and in the "Get Started" tab, under "Start" Click on "Clone Git Repository" and paste the URL of your forked Repository. After creating files for the repository click on View -> Terminal or shortcut: ^` for Mac.
git status" - The command is used to display the state of the working directory and the staging area, it also shows which files have been tracked (Added to staging area) and untracked (Not Added to staging area).
git add" - The command is used to add files to the staging area and it's syntax is "git add filename.extention".
Let us take an example, where we have created a file called "text.txt". When you open the terminal in VS code type in "git add text.txt". To check if the file has been staged, use the "git status" command and the following should appear.
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
(use "git restore --staged ..." to unstage)
new file: text.txt
In the terminal untracked files will appear in red and tracked as green.
git checkout" - The command is used to change between branches in the repository. In this example, I have created a new branch called "demo" using the "git branch branchname" command. So to change the branch, the syntax would be "git checkout branchname", in this case, it would be "git checkout demo" and the following should appear.
git checkout demo
Switched to branch 'demo'
git commit" - The command is used to create a snapshot of all the changes made to the repository and will not be changed unless asked to and this will be "pushed" to the main repository. The syntax of the command is "git commit", if you would like to add a message to the commit, type the command as
git commit -m "Enter message here" , and if you use the command as is, it will open a message editor where you enter the message for the commit and exit that screen type ":wq".
So this is how it should appear after using the command.
1 file changed, 1 insertion(+)
create mode 100644 text.txt
git push" - The command is used to push all the changes in your repository to the main repository. When you use the command the following should appear.
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 254 bytes | 254.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To [The URL of your repository]
Here are a few sources for those who are interested in learning Git.
I hope this helps, I am too learning git and if you have any feedback on how I can improve or any changes to make, please feel free to reach out!