Git can be a real pain in the posterior regions of yours when you are new to it. There are thousands of blogs explaining what is git…But i’ve tried my level best to make it different from them. So you can really answer this :-
Bro, do you even GIT it ?
What is Git?
Git is a version control system (VCS) . It is generally used to keep track of revisions and allow a developer or dev team to work together on a project through branches.
Outside code development it is also used for keeping track of non-binary files such as financial reports.
Git is not GitHub. Git is the system, and GitHub is a repository hosting service (the most popular of many).
Tower, SourceTree, Github for Mac/Windows — these are all GUIs, or Graphical User Interfaces. A GUI is a program that utilizes graphics to create a user-friendly experience, such as Windows to MS-DOS. These programs are useful to learn, especially in a team environment, but in this article, we’re going to do everything through the command line. Don’t worry, it’ll be great.
After all this technical introduction i know what you are thinking….
So what we’ll do is
- We’ll make one github repo on our own and learn what does all these technical jargons mean .
- Follow along ,life will be a little simpler now…atleast the part of your life which includes GIT.
Step 1: Installation
Open the Terminal program. Type git — version and press enter. If a version number is returned, Git is already installed. If something along the lines of -bash: git: command not found pops up, install Xcode from the App Store.
In XCode, install Command Line Tools: > Preferences > Downloads > Command Line Tools. You can now use Git through Terminal.
Although it’s not necessary for the rest of this article, now would be a good time to install Homebrew — a tool for simplifying the installation and management of dev tools.
Download Git for Windows. You will be using the Git Bash program. It will utilize all the same commands as Terminal.
Step 2: Create an Online Git Repository
GitHub is the most popular location to host repositories, so go ahead and make an account there if you haven’t.
I’ll assume your username is kamlesh. This would make your new GitHub https://github.com/kamlesh.
Once you’ve made your account, create a repository by clicking Add New Repo. Do not initialize with a README.md or .gitignore at this point. We can call the repository project. Your repository has been created at github.com/you/project. It should be completely empty.
Step 3: Create a Local Project
If you’re not at all familiar with the command prompt, please read the first chapter or two of the command line crash course or you can follow along the article and come back to it again later.
Here are the most important commands, and all you need to know to get started.
Basic command line reference
- pwd Print Working Directory — shows the exact directory you’re working in.
- ls List Directories — lists all the files and folders in your current directory.
- cd Change Directory — change to another directory.
- mkdir Make Directory — create a new directory.
Remember, Terminal (Mac) and Git Bash (Windows) are both command line shells. Any Git related Shell commands can be done the same through both.
When you open Terminal, you will start off in your main directory. I will assume your computer has the same username as your GitHub account.
Now open git bash(if on windows) or terminal(if on OSX or Linux) and type the following command and hit enter after each.
The code written succeeding (->) is the output of your command, you need not type that.
- Confirm your location.
2. Create a new folder called project-local.
3. List your directories.
You should see project-local in the list of directories. Of course, you could have created the directory through Finder or Explorer, but it’s a useful command to know.
4. Move into the newly created directory.
Now you’re in the folder where your local project and Git repository will live. From here, we will begin using git commands. There is a massive amount of commands for Git, but we only need a few to get started.
Basic Git command reference(Not to be used now ,just for reference)
- Initialize Git repository
- Check the status of a Git repository
- Track files
- Commit tracked files
- Upload files
- Download files
All of the future commands we do today will only apply to your local Git environment. However, there is one important global step to take before doing anything else — configure your Git account.
5. Configure your global Git account.
git config --global user.name “Firstname Lastname”
git config —-global user.email firstname.lastname@example.org
Make sure you’re still in the project-local folder, then move on.
6. Initialize Git repository.
Initialized empty Git repository in /Users/you/project-local/.git/
Great! Now you have an empty Git repo on your local computer.
7. Hook up local directory with the repo we made at github.com.
git remote add origin https://github.com/you/project
Terminal won’t respond, but it was successful. Go ahead and add a file to the project-local directory. You can add as many files as you want, but I will assume you added two files –index.html and style.css.
8. Check the status of your local repository.
git status-->On branch master
-->Initial commit-->Untracked files:
-->(use “git add …” to include in what will be committed)-->index.html
-->style.css-->nothing added to commit but untracked files present (use “git add” to track)
Okay, so now it knows that there are two files in the directory, but they’re not a part of the Git repo. At this point we have to track the files with the add command.
9. Add ALL the files to the repo. (case sensitive command!)
git add .
Let’s check the status again with git status.
-->On branch master
-->Initial commit-->Changes to be committed:
-->(use “git rm –cached …” to unstage)-->new file: index.html
-->new file: style.css
So, what did that do? The files are green now instead of red. Are we ready? Not quite yet.
10. Commit tracked files to the master branch
git commit -a -m “Initial Commit”-->[master (root-commit)] Initial
-->2 files changed, 34 insertions(+)-->create mode index.html
-->create mode style.css
With this command, I commit all the files (-a), include a message (-m), listed here (“Initial Commit”). Everything in this line is mandatory.
Do not forget to add a comment when you commit your files. Strategic commenting in Git is as important as commenting code. If you accidentally forget to add a comment and end up in a strange screen where you can no longer enter any commands, press ESC and type :q! followed by ENTER.
11. Push the files to the Git repo at github.com.
git push origin master
Terminal will prompt you to enter your GitHub username and password. When you type in your password, it might not show that you’ve typed anything, but it’s being entered.
Now refresh your GitHub page. Success! All your files are now hosted at Github.com!
CELEBRATION TIME !!!!!!!