Skip to content

Instantly share code, notes, and snippets.

@martinvelez
Last active March 17, 2018 02:31
Show Gist options
  • Save martinvelez/a335c7070e67082f00ae0031b719f2e9 to your computer and use it in GitHub Desktop.
Save martinvelez/a335c7070e67082f00ae0031b719f2e9 to your computer and use it in GitHub Desktop.
A super simple guide to Git

The 7 Most Important Git Subcommands

Git allows you to get a project's source code, make changes to it, and share those changes with your teammates. That's pretty much it. Unfortunately, it introduces a lot of concepts and terminology that often confuse beginners. Its command-line interface makes it even harder to see the whole picture.

But there is hope. You do not have to learn all of it to use it. I have been using git for several years now and use about 20 commands. But in any given day, I only use 7!!!

  1. clone
  2. pull
  3. status
  4. add
  5. rm
  6. commit
  7. push

clone: Download a repository

This command download's a project's source code. You will usually execute this once per repository. The following command will create directory called docs in the current directory and download the git project there.

cd ~
cd github
git clone https://github.com/kodethon/docs

pull: Get changes from others

Note: Unlike clone, this and the rest of the commands have to be executed within the git repository.

This command synchronizes your local copy with the central copy. You will run this command often.

cd ~/github/docs
git pull

status: What files have you changed?

This command will let you know which files have been added, modified, and deleted.
You will run this command often.

git status

add: Add a file or directory.

This command lets you choose which files to include in this change.

git add README.md

rm: Remove a file or directory.

This command deletes a file from the git tree and the local disk.

commit: Create a commit

This command lets you create a "commit". A commit is like a checkpoint. It identifies a specific point in the history of the project.

git commit -m 'Clarified installation instructions.'

push: Upload your changes.

This command lets you upload your changes to the central copy. If the command succeeds, others can download your new changes to their local copies.

git push

Conclusion

Do not be afraid of using git. Most workflows will require that you learn only a small subset of all the available subcommands. Learn more as you need them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment