git
Git commands
In this blog post will be my first git cheat sheet in order to learn git better.
This assumes you already have a local git repository in your computer
This post is based on this video link
Commands
-
git init –> link a folder as a repository in github
-
git status –> tells your the status of your folder e.g. which changes have been made, if you are in the master branch, etc.
-
git add filename –> add file to staging area (see the video to understand what stagging area is)
-
git commit –> commit or save changes from stagging area to master branch. Note: this command will send you to VIM page. Write the commit message and then press : and in the cursor that appear press x.
-
git config –global core.editor “nano -w” –> changes the text editor to nano (so VIM won’t appear again)
-
git commit -m “write message” –> commit writting message directly. Note remember before commit add file to stagging area
-
git log –> reverse chronological list of all messages you made
-
–oneline –> gives one first digits of each message code
-
log opens an annoying program called less. Press q to exit the program
-
-
git dif –> differences between two changed versions of a file. Gives first changed version and then current version.
-
sometimes when files in stagging area have been changed, diff alone won’t show changes. Use diff –staged in that case
-
HEAD ~number filename.txt –> compares changes between latest change in file and commit number of steps below
-
you can also enter the commit code directly
-
-
git add . –> changed all files that were changed
-
git checkout HEAD file.txt –> undo changes to that file before commit, or recover deleted file
- git checkout master –> brings you back to the master
-
git reset –hard –> reverse back to last state
- git reset HEAD file.txt –> un-add file.txt if was already added
-
.gitignore –> this file has all files or extensions that git will ignore
-
git remote add origin https:github.io/username/repository.git –> add repository as origin
- git remote -v –> see if repository was added succesfully
-
git push origin master –> send commits from local machine to remote origin master branch
- git push -u origin master –> sets default to where push changes
-
git pull origin master –> pull changes from remote origin to local computer
Leave a Comment