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"
- Sets the name for the author of the commits transactions.
- 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
- Starts a Git repository on a existing directory.
- Downloads an existing repository from GitHub using HTTPS. You’ll have to enter your GitHub password.
- 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
- Creates a new branch.
- Deletes the branch.
- Switches to the branch.
- 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"
- Adds the changes made on the file to the commit you’re creating.
- Same as 1, but adds all the modified files of the directory (recursively) that weren’t added before.
- Same as 1, but with multiple files.
- Removes the file from the repository.
- 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
- 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.
- Shows all the stashed changes.
- Pops the latest changes stashed to the working tree.
Synching local and remote files #
$ git pull
$ git push
- Updates the local repository with the new commits from the remote repository.
- 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!