Ayomide Ibosiola
5 min readApr 2, 2021

--

Working with Git — GitHub

I decided to make a summary of what I have learnt recently on Git commands for my friends who have been having issues communicating with GitHub. Of course, I can bet that you were not told by your tutor or that your developer friend that Git needs to be learned separately. All you probably thought about learning to be a great developer at the start was how to write codes; nothing more. The good news is that Git has a smooth and simple learning curve.

You know that besides writing great code, you would have to collaborate with other developers to build great products. Yeah?

All the documents I used in learning before deciding to put together this resource make Git look like a piece of cake. Well, it is my dear.

Git and GitHub are not the same thing.

While Git is an open-source version control tool created by developers working on the Linux operating system, GitHub is a company that makes tools which integrate with Git. You do not need GitHub to use Git, but you cannot use GitHub without using Git. There are many other alternatives to GitHub, such as GitLab, BitBucket, e.t.c. A firm grasp of either of these makes storing your code and sharing your code with others easier.

To confirm you have Git installed on your machine, run git–version command on your preferred code editor terminal.

Use this information to help Git identify you as the author.

$ git config — global user.name “YOUR_USERNAME”, and

$ git config — global user.email “ayomideibosiola100@gmail.com”.

Use $ git config — global — list # to check the information you have just provided.

To initialize a Git repository in the root of the folder, run the git init command.

· git add (git add .or git add *)is a command used to add a file that is in the working directory to the staging area.

· git commit -m “message” is a command that indicates an individual change to a file (or set of files). Combined with git add, this defines the basic workflow for all Git users. A commit is a record of what changes you have made to your code. Essentially, you make changes to your repository (say you get to add or modify a file) and then tell git to put those changes into a commit. Commits make up the essence of your project and allow you to jump to the state of a project at any other commit. Enter a relevant commit message to indicate what code changes were done in that particular commit.

· git push is a command used to add all committed files in the local repository to the remote repository. So, in the remote repository, all files and changes will be visible to anyone with access to the remote repository.

· git fetch is a command used to get files from the remote repository to the local repository but not into the working directory.

· git merge is a command used to get files from the local repository into the working directory.

· git pull is a command used to get files from the remote repository directly into the working directory. It is equivalent to a git fetch and a git merge.

· git remote manages the set of remotes that you are tracking with your local repository.

· git remote -v lists the current remotes associated with the local repository

· git remote add [name] [URL] adds a remote

· git remote remove [name] removes a remote

Ever wondered what ‘set URL’ means and how to set URL in GitHub?

You will see ‘origin’ a couple of times in this session; origin is an alternate name for your remote repository so that you don’t have to type the entire path for remote every time. Use this newly declared name (origin) to refer to your remote. This name could be everything.

To verify that the remote is set properly, type git remote –v OR git remote get-url origin.

Use git remote set-url origin git@github.com:https://github.com/ayomideEnoch/portfolio.git or git remote set-url origin https://github.com/ayomideEnoch/portfolio.git if at any stage you wish to change the location of your repository (i.e. if you made a mistake while adding the remote path using the git add command) the first time, you can easily go back and “reset (update) your current remote repository path” by using the above command.

What is a branch?

Ever seen one in a tree?

If yes, a branch in Git is similar to the branch of a tree. Analogically, a tree branch is attached to the central part of the tree called the trunk. While branches can grow out and fall off, the trunk remains compact and is the only part by which we can say the tree is alive and standing. Similarly, a branch in Git is a way to keep developing and coding a new feature or modification to the software whilst not affecting the main part of the project. We can also say that branches create another line of development in the project. The primary or default branch in Git is the main branch (similar to the trunk of a tree). As soon as the repository creates, so does the main branch (or the default branch).

Why create a new branch?

Git branches come to the rescue at many different stages during a project development. As mentioned above, branches create another line of development that is entirely different or isolated from the main stable master branch. There are many advantages to doing so. Consider that you are developing a project with your team and you finish a feature, you contact the client to request them to see the feature but they are too busy, so you send them the link to have a look at the project.

Switch to another branch

git branch –m new-branch

NB: You need not make a commit i.e. do git add .(or git add *) and git commit –m again to the branch you just switched to if the other branch contains your most recent update. However, you need to use git push –u origin head to push to this branch.

Delete a branch

To delete a branch, use git push origin --delete branch-name-to-be-deleted

What does status mean?

Status is the situation at a particular time during a process.

The git status command displays the state of the working directory and the staging area. It lets you see which changes have been staged, which haven’t, and which files aren’t being tracked by Git. Status output does not show you any information regarding the committed project history.

The git pull command is meant to be a convenient shorthand for git fetch followed by git merge. Like git fetch, git pull takes the name of the remote/origin. The main thing git pull does with this is hand it off to git fetch.

Credit to Victor Ibosiola and Joseph Oyeniyi for their support via proofreading and copy editing.

--

--