GitHub basic commands, Tips, and tricks

Dec 19, 2022

What is GitHub?

GitHub is a website and cloud-based service that helps developers store and manage their code, as well as track and control changes to their code. It lets you and others work together on projects from anywhere. Git is a distributed version control system, which means that the entire codebase and history are available on every developer’s computer, which allows for easy branching and merging.

Difference between Git and GitHub

While Git is a tool that's used to manage multiple versions of source code edits that are then transferred to files in a Git repository, GitHub serves as a location for uploading copies of a Git repository. In a sense, then, there's no comparison when it comes to Git vs. GitHub as far as their function.

Three primary actions:

  1. Fork: The process of copying another’s code from the repository to modify it.
  2. Pull: When you’ve finished making changes to someone else’s code, you can share them with the original owner via a ‘pull request’.
  3. Merge: Owners can add new changes to their projects via a merge, and give credit to the contributors who suggested them.

To sum up the difference between Git vs GitHub:

  1. Git is a local VCS software that enables developers to save snapshots of their projects over time. It’s generally best for individual use.
  2. GitHub is a web-based platform that incorporates git’s version control features so they can be used collaboratively. It also includes project and team management features, as well as opportunities for networking and social coding.

How to Integrate Git?

Step 1: Install git and Add a Repository

Download the git software for your Operating System (OS).

Once it’s up and running, there are a few terms you’ll want to familiarize yourself with as you start using the software:

  1. Repository: The file location where your project is stored.
  2. Commit: The command is used to save new changes to your project in the repository.
  3. Stage: Before you can commit changes in Git, you need to stage them – this gives you the chance to prepare your code before formally adding it to your project.
  4. Branch: The part of your project you’re actively developing.

To connect Git to GitHub, you’ll need to add a repository and make at least one commit. You’ll then have enough of your project established to start working in GitHub.

Step 2: Add a GitHub Repository to Your Account

After you’ve created, you’ll need to create a repository in GitHub where you can store your project when you move it over from git. You can do so by clicking on the relevant link in the left-hand sidebar:

Then, you’ll need to choose a name for your repository:

You can also decide if you want the repository to be public, so other GitHub users can find and contribute to it, or if you want to keep it private.

Either way, since you’ll be using an existing project, make sure to leave the Initialize this repository with a README box unchecked.

Step 3: Push a Repository to GitHub

Next, you’ll have the option to add code to your repository in a few different ways.

Since you’ve already set up your git repository, you can use the push an existing repository from the command line option:

The clipboard icon to the right enables you to copy the commands listed here, so you can quickly paste them into your preferred command-line interface to create your GitHub repository.

Once that’s done, refresh your GitHub page:

You should now be able to see your repository in GitHub. From there, you can start making changes to your project online.

It’s also possible to send and merge pull requests, and use any other tools included with your plan.

Step 4: Pull Your Changes Back to git

While you can see all the changes you and others have made to your project on GitHub, the platform doesn’t have direct access to your computer’s files. To keep your project up-to-date on your computer, you’ll need to pull your edits via git.

To do so, simply enter git pull origin master into your command-line interface. This should update your files so that everything is in sync across all iterations of your project.

What are the Most Common Git Commands?

  1. To rename the branch: git branch -m new-branch-name
  2. Combination of add and message: git commit -am "message"
  3. Show all commits in the current branch yet to be merged to Master: git cherry -v master
  4. Modify the previous commit without modifying the commit message: git commit --amend --no-edit
  5. To unstage new file use: git rm --cached

Git status - short status flag

?? - Untracked files

A - Files added to Stage

M - Modified files

D - Deleted files

Tips and Tricks

  • To Open GitHub CLI: Type (>) or type github1s.com in the GitHub link.
  • To send a function: Inside the repository open any function, copy the URL, and send it.
  • To send a line: Type #L and the line number in the URL to be copied and send.

Conclusion

Git is a powerful tool and is full of neat tricks. Of course, there are more tricks you can learn, but I hope that this series of articles help you.

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.