Let’s Git Init…

Joshua Singleton
6 min readOct 18, 2020

--

GitHub

This is a step by step guide on how you and your team can use one of the most highly used version control systems on the market, Git Hub.

“ GitHub is a code hosting platform for version control and collaboration. It lets you and others work together on projects from anywhere.” — GitHub

GitHub is a great platform to use to collaborate work. We can utilize GitHub to work on pieces of a project independently and seamlessly unite it together in the end.

There are many blogs on how to use GitHub and the functionality. For a tutorial on how to use the Github website check out this link! However, I am going to show you how to use Git through your terminal on your computer. Let’s git started:

Sign into your Github account an create a new repository for your project

Git Hub Profile page

Click on your profile icon in the corner and select your repository.

Create a new repository

Give your repository a name and description.

You have the option to initialize your repository with a few options:

  • Readme File
  • .gitignore
  • License

For this example I will just add a README file.

And click on Create Repository

Blog on SSH Clone
  • Now click on your newly created repository and click on the code icon.
  • Once open, make sure you choose SSH clone option. By choosing SSH, you are cloning with a secure key so that you can upload to this repository without having to log into Git hub from your terminal.
  • Click the clipboard icon to copy the link.

Once you create a directory on you computer for your project, open your terminal and access your directory…

  • Type “ cd + your project directory name
  • Type “git init”! This command creates an empty Git repository or reinitializes an existing one
  • Type “git clone + repository link”.
  • After cloning, change the directory to that repository and open it up in your code editor (I am using Visual Studio)

We now have a local clone of our project. At this step, there are a few things to point out here:

  • This is now a remote copy of the main branch. Your branch inherits everything that was on the main branch.
  • A local branch is a branch that only we (the local user) can see. It exists only on our computer. The “git branch” command can show us our local branches
  • When you first start on your local branch, you will still be on your main branch as indicated on the bottom. Any changes(commits) you do will go on the main branch. You can also check what branch you are on by typing ‘git branch’ in the terminal. The one you are on will have an asterisk next to the name.
  • If you would like to make changes without affecting the main branch, create your own local branch by typing ( git branch ‘new-branch-name’) in the terminal. If you type ‘git branch’ in your terminal, you can now see the new local branch you created. To change to that branch type “git checkout (new-branch-name)”. Confirm you are on that branch now by typing “git branch”. The asterisk should now be next to the new-branch-name.
Creating and changing to a new branch
  • To create a new branch and move onto that branch in a single command, type “ git checkout -b new-branch-name” in the terminal
  • To switch to any branch that we’re not currently on type “git checkout other-branch-name
  • To switch back to the previous branch type “git checkout -
Creating and changing branches
  • Type “git log” to see any and all changes done in your repository
  • Type “git status” to confirm the changes you made

Modify your project by “Adding” changes

  • If we made a few changes throughout the file and want to see what changed, we can review changes in ‘chunks’ by typing “git add -p
  • If we know we want all the changes in a file we can add the whole file by typing “git add file-name
  • If we know we want all the changes in all the files in our current directory, type “git add .”
  • If we want all the changes to all the files in a sub-directory, type “git add name-of-sub-directory/.” — ex. “git add images/.
Adding to our project

Git to Commit

Now that you have made changes, its time to commit those changes to the project.

  • To commit the changes that have been staged so far type “git commit -m <message>
  • It is always a good practice to be very descriptive with your messages as this allows for great communication within your team!

Git to Pushing

So far we have done a lot..

  • Made a clone of our repository
  • Set up a local branch of that repository
  • Made changes on that local branch
  • Added those changes
  • Save those changes by committing them

Now it is time to make these changes assessable to others through our git hub

  • Type “git push”. This is if the branch exists on the remote and we have used the previous command before.
  • If we have a branch that does not exist on the remote repository type “git push -u origin “new-branch-name”.
Committing and Pushing Through

Now if you look on your Github account, you can see that your repository has been modified

Bill Withers adding to my life beyond the grave
  • Click on “Compare & Pull request”.
Merging branches

Thankfully, there were no conflicts with the base branch. I will update this blog once I do run into that issue (Stay tuned…)

  • Click on “Merge pull request”
Changes are updated to our Github account

And there you go. You are done. You can definitely make it if you try. You can work with groups of people on a project. Remember we have to go for all we know. You can make great projects with those around you… Maybe You and I.

link to learn Git Work flow

--

--

Joshua Singleton
Joshua Singleton

Written by Joshua Singleton

Student of Code in the hopes of creating a new social network to enhance the community!

No responses yet