Source Control: Git The Console 1.0v
To all my aspiring programmer friends.
Welcome, I think it won’t be wrong of me to assume that you are here to know about Git, Just to let you know it’s GIT and not GitHub.
Git in this post basically means that old hard way of console (command line) work { which for me is more fun}. I will make sure that you will be able to use basic Git commands after reading this post.
GitHub is based on git Technology for source control.
Thou, have been chosen ,young programmer, to face the challenge of version control….
A bit about version control { source control in general } before starting git.
Let’s begin
- Version control
Version control, simply means that your every change is stored as a record in the system(local or remote). It is done so that new features or changes can be added safely without the concern of breaking the previous work. If anything goes wrong after changing you can easily go back and start again ;)
Also, when you are doing a group project, and everyone needs one copy of the code to work on, the Change integrity is very difficult to manage and deploy, and bugs and fails are hard to fix if anything goes wrong. Version control helps in the integrity of the ever-changing data.
2. Why Git?
You can use it offline, as everyone will have their own repository, you can easily branch off to a new side and merge back. No permission to add your code? No problem, commit them offline in your own system. Benefit others with your work as you send pull requests to others.
Liked someone’s project? Easy clone it. Git’s flexibility allows you to move back and forth among commits. its flow is like a water slide, you enjoy the Ride. Join the decentralized Version control system that spans to millions of developers.
Still not convinced? well, don’t be disappointed here are your other options-: Mercurial, CVS, TFS . Ctrl-Z is your Best friend anyway ;)
Let’s get Started, shall we?
Git is a multiplatform version control system, you can get download it from the official website on any platform, Windows, Linux, macOS, and it works basically the same at all platform. Link
If done correctly, go to your preferred folder and right click and select git bash.
Before we could jump into Git commands let’s learn a few useful bash commands…
1. ls -: (list) show a list of the number of items present in the working folder
2. cd -: (change directory) it allows you to change the current Directory/folder.
3. cp -: (copy) it allows you to copy one item to another directory/folder
4. mv-:(move) it allows you to move the item from one folder to another
5. mkdir -: (make directory) it allows you to make a new directory/folder
6. rm -: (remove) to remove a file { use rm -rf to forcefully delete a folder }
Watch this video for better clarity of bash commands.
Welcome to Git commands
You need to tell git who you are and how to contact you. You do this by typing this commands-:
$ git config —-global user.name “John Doe”
$ git config — -global user.email “johndoe@example.com”
Suggestion-: Give the name and email that you have on GitHub
Now you are all set to Go……
Workspace -: This where you work and edit code, using any text editor
Staging -: Once you add files they come to the staging area.
Local Repository -: once you commit( you tell git that these are your final changes and Git has to save them permanently) they reach the local repository.
Remote Repository -: These are the repository available on your Github, Gitlab etc. account that you can link with.
Making a new git Repository with a remote connection (Github)
A. Give a name to your Repo
B. Tell something about what you will be uploading in the Repo
C. A choice for you, public or private?
D. A readme.md file which will show up in the repository which further describes your whole repository.
E. .gitignore, file and extensions registered in this will not show up in the git staging area.
F. Congrats, you created your First Repo.
Back to bash
Use the given commands to make a local Repo and push it to Remote Repo.
Suggestion: Don’t use echo “ something” >> README.MD, Rather do changes after completing the connection between local and remote Repo
Step 1: git init
This will make Your folder a local Git Repository
Step 2: git add Filename
{ Make sure the files that you want to put in the repository are present in this folder} This will add the file to the Staging Area.
Step 3: git commit -m “ what did you add”
This will tell git to save your changes with a small description which type after -m { -m means message, and “ what did you add” is a small text telling what changed or what got added }
Step 4: git remote add origin <Repo Link>
This will assign the link to the word “origin” so that you need not to paste this link again and again.{The Link is given the moment you make a remote Repo}
Step 5: git push -u origin master
This tells git that the committed changes are to be pushed in the remote Repo link { origin} on the branch of master.
Suggestion: you can do a “ git pull/fetch origin master ” after Step 4, for creating a proper connection. { you can edit the readme file now using a Text editor }
Congratulation you learned how to create a git Repo { both local and remote via CLI}
Origin -: Is not a command, you can have any name { MyOrigin, SourceOrigin etc}
Master -: Is the main branch of all new repositories.
suggestion-: Use “ git status” at any point to get more details
suggestion-: Press tab to do an autocomplete, git sta{tab} -> git status
Now as you have learned how to add your work to Remote Repo, you can also download Remote Repos’ of other that you like.
Cloning
On Github go to the Repo you like to download/Clone and then go to the download button, you will see a link, you need to copy that.
Go to the folder you want to be used for this Remote Repo, and right click to get the GitBash.
use this command-:
git clone <Download Link>
Now you have your own copy.
Understood?
I can understand, it is not really easy to grasp all the things written above along with commands.
You will face many problems before you can truly master git.
You have learned enough that till you master git you can do as this cartoon says. ;)
Just Kidding, or you can actually do that too, that’s Git you know.
Happy Coding…….
Thanks for Reading
By -: Adarsh Kumar