Familiarity with Git caused some uncertainty. So I decided to make a list and a description of the git commands for the terminal.
Here I use a terminal (you can also use a terminal in VS Code), pre-installed Git (here) and my page on GitHub.
What is Git and why do we need to use it?
Git is a distributed free and open source version control program. It is a program that is needed for developers to be able to keep track of changes to program code made by other developers, and be able to make consequential changes if needed.
GitHub is a web service for software development where all participants have the opportunity to save their changes to an ongoing project and get an overview of how the project is progressing. So developers should be able to handle version management with the help of git both locally and on their web service (externally).
By having git installed on your local device, you can handle version management both locally and externally on GitHub. Should your program code disappear locally for any reason, you can always find the latest uploaded code on GitHub.
Here are the commands that will be described in the post:
- git --version;
- git --help;
- git --init;
- git status;
- git add .;
- git rm --cached filename;
- git commit -m "";
- creating a .gitignore file;
- git branch;
- git branch branchname;
- git branch -D branchname;
- git checkout branchname;
- git checkout -b branchname;
- git merge branchname;
- git remote add origin https://... .git;
- git push -u origin branchname;
- git --version
Prints the Git suite version that the git program came from.
- git --help
Prints the synopsis and a list of the most commonly used commands.
- git --init
cd .git ls
- git status
- git add index.js OR git add . (to add all files)
- git rm --cached filename
If at this stage we will make changes to the file in VS Code, it can also be seen with the command git status.
We see that the index.html file has been modified, so we need to add it again using the git add index.html command.
- git commit -m ""
If we have certain files in a folder that we do not want to commit, then in VS Code you can create a special .gitignore file in which you can write the names of files or folders that we do not want to commit. It will look like this.
The .gitignore file must be committed.
- git branch
- git branch branchname
- git branch -D branchname
- git checkout branchname
- git checkout -b new
- git merge branchname
git remote add origin https://... .git
git push -u origin branchname
Next, you need to run two more commands in the terminal, which are listed on GitHub. They can simply be copied to the terminal. The only thing you need to consider is the name of the branch in git push -u origin main. In my case it will be git push -u origin master.
Once the file is committed, it can be seen on GitHub.
You need to go to the file page and click on the "commits" button.
Next you need to click on the desired commit code.
Here we see the changes made to the file. Red - what has changed. Green indicates changes.
Thank you for your attention! Hope this is helpful.