In this article we learn the what is git and github, how to install on windows and also learn the which commands are most used.
What is Git and GitHub for beginners?
Git is a version control system that you manage and keep track of your source code history.
GitHub is a code hosting platform for version control and collaboration. We can create repositories of our project and save our project there.
It gives other people a way to navigate our repos.
It makes repo collaboration easy (e.g., multiple people contributing to the same project).
A Version Control System is a utility or software which helps us to track and manage changes to a file system or code repo for better collaboration among developers to develop an application. It can keep history of changes into a file including who has changed and what was changed.
How To Install GIT on Windows: –
Navigate to the download page of GIT. (https://git-scm.com. On this page, you will find the latest version of GIT and the download link for Windows. It automatically shows the download link based on the operating system of our PC.
Click on the “Download for windows” link. you will see download is happening. It will download a file named Git-22.214.171.124-64-bit. Please note download file has the current GIT version.
Double click on the downloaded executable file of GIT. It may show a popup for permission to make changes which you should allow.
It will show an information page containing terms and conditions. If you are interested to read all those paragraphs then do that and click on Next otherwise you can directly click on the Next button.
Select the destination location [c:Program Files Git] where GIT will be installed. You can continue with the default location as shown below or you can change it. Click on Next.
In this step you need to select components to be installed. I will recommend going with the default selection. GIT Bash and GIT GUI are major components that are default selected. You can also check Additional icons on the Desktop. Click on Next.
Select if you would like to GIT shortcut in the start menu. Go with default selection and click on Next.
Select the default editor of GIT. We use Notepad++ as the default editor used by GIT. You can select any option in the dropdown. There are many options available.
Now this is a new feature of GIT. If you are little aware of GIT then you may know the default branch name used by GIT is master. This can be customized now. As of now, you can go with the default branch name and click on Next.
Now you need to set up how you would like to use GIT from the command line. Use the recommended option as there will be no need to set up any environment path. Click on Next.
Select SSL/TLS library used by GIT to use for the HTTPS connection. Go with default selection and click on Next.
Configure how GIT should treat line endings in text files. Click on Next with default selection.
Configure the terminal emulator to use with GIT bash. As we have already selected to install GIT Bash as well. Click on Next with default selection.
Configure the default behaviour of the git pull command. Continue with the default selection and click on Next.
Choose a credential helper. It has a new option now called Git Credential Manager Core. It is a cross-platform version. Go with default selection and click on Next.
Enable file system caching to boost performance which is default selected. Click on Next.
Configure experimental options. These two features are new and optional. Suggest you check “Enable experimental built-in file system monitor “. This will be the last screen of setup and now click on Install.
Installation will start and should take less than 1 minute.
You will get below screen after successful installation of GIT. Check “Launch Git Bash” and Click on Finish.
What is git init?
The “git init” command creates a new empty git repository or initializes an existing directory as a git directory. Once the directory is a git directory you can run any git commands.
Can we rerun the “Git init” command again on a git initialized repo?
Yes, we can, and It will not override an existing “. git” configuration.
What is git Status?
“git status” shows that there are untracked files. It displays the state of the working directory or of the branch where you are currently working. It lists which files are staged, unstaged, and untracked.
Untracked files are files that are present in the working directory but have not been added to the repo’s tracking index. In short, git is not tracking any changes to those files till we explicitly add them using the git add command.
When we run git status commands then it actually compares what has changed from the last commit of the currently checked-out branch.
What is git add?
- When we add a new file that time it was untracked. After running the “git add” command file status moved to “changes to be committed “. It is also called file is staged for commit or file is in a staging area.
1) git init ->Create empty Git repo in specified directory. Run with no arguments to initialize the current directory as a git repository.
2) git add->Stage all changes in <directory> for the next commit. Replace
<directory> with a <file> to change a specific file.
3) git config –global user.name” “->Define the author name to be used for all commits by the current user.
4) git config –global user. email” “->Define the author email to be used for all commits by the current user.
5) git commit -m “ “->Commit the staged snapshot, but instead of launching a text editor, use <message> as the commit message.
6) git remote add origin ‘paste url of repository’->Create a new connection to a remote repo.
git push -u origin master-> Push code to local repository to remote repo.
Create folder->Right click and Select git bash here.
1) git clone ‘ Repository url paste here’->Clone repo located at onto local machine. Original repo can be located on the local filesystem or on a remote machine via HTTP or SSH
C) <Change branch>
1) git branch->List all of the branches in your repo. Add a <branch> argument to create a new branch with the name <branch>.
2) git branch ‘branch name’->Create new branch.
3) git checkout ‘branch name’-> Create and check out a new branch named <branch>. Drop the -b flag to checkout an existing branch.
4) git push -u origin ‘branch name’=> push code old to new branch
5) git merged ‘branch name’-> Merge into the current branch.
6) git branch -d <branchname>->Delete the branch.
1) git status-> List which files are staged, unstaged, and untracked.
2) pwd-> Present Working Directory
3) cd->Change Directory
4) git stash clear-> Remove all stashed entries
5) git rm -r [file-name.txt]->Remove a Folder
6) git diff=> Show difference between working directory and last commit
7) git log -p-> Display the full diff of each commit.