Skip to main content
  1. Posts/

Basic Git commands

·2 mins· loading · loading · ·
Programming Version Control Git Shell
Author
Jessica Patricio
Full Stack Developer. BSc in Computer Science. Passionate about programming. Believes in a more accessible and inclusive internet.
Table of contents

Hey! How are you today?

I was studying some specificies of GitHub and it came to me that I should really understand the basics before going into something harder. So I’m writing this post to help me to remember the purpose of these Git commands.

Initial Git settings
#

$ git config --global user.name "Your Name"
$ git config --global user.email "youraddress@mail.com"
  1. Sets the name for the author of the commits transactions.
  2. Sets the e-mail for the author of the commits transactions.

Starting a project
#

$ git init
$ git clone https://github.com/github-username/repository-name.git
$ git clone git@github.com:github-username/repository-name.git
  1. Starts a Git repository on a existing directory.
  2. Downloads an existing repository from GitHub using HTTPS. You’ll have to enter your GitHub password.
  3. Same as 2, but using SSH. You’ll have to previously register an SSH Key on your GitHub settings.

Setting branches
#

$ git branch branch-name
$ git branch -d branch-name
$ git checkout branch-name
$ git merge branch-name
  1. Creates a new branch.
  2. Deletes the branch.
  3. Switches to the branch.
  4. Merges the branch “branch-name” into the current branch. This article explains it better.

Making changes
#

$ git add file-name
$ git add .
$ git add file1 file2 file3
$ git rm file-name
$ git commit -m "Description of the changes made"
  1. Adds the changes made on the file to the commit you’re creating.
  2. Same as 1, but adds all the modified files of the directory (recursively) that weren’t added before.
  3. Same as 1, but with multiple files.
  4. Removes the file from the repository.
  5. Adds a descriptive message for the modification on the files you added to the commit.

Basics of stashing
#

$ git stash save "Description of the changes made"
$ git stash list
$ git stash pop
  1. Saves the changes made since the last commit into a stack, so you can return to them later, with no need to commit them yet.
  2. Shows all the stashed changes.
  3. Pops the latest changes stashed to the working tree.

Synching local and remote files
#

$ git pull
$ git push
  1. Updates the local repository with the new commits from the remote repository.
  2. Uploads the commits from the local repository to the remote repository.

That’s it for now.

There is a whole bunch of other commands on the Git documentation and I think it’s important to know about them too, but we’ll get there.

Maybe I’ll do a part two.

Stay safe!

References
#

Related

Standards for Git commit messages
·3 mins· loading · loading
Programming Version Control Git
Suggested practices for writing good Git commit messages
Using virtualenv in Python
·3 mins· loading · loading
Tutorial Programming Python Pip Virtualenv Shell
Creating and managing a virtual environment in Python