Git Cheatsheet
Git is a version control system, another great invention of Linus Torvalds. This will be a basic cheatsheet containing common git commands targeted at beginners. See the links in the bottom for advanced git cheatsheets.
Common git workflow
To create (initialize) a git repository
|
|
To clone a remote git repository
|
|
To see the current status of the working directory
|
|
To add files [to the staging area] for commiting
|
|
Once you added files [to staging area] for commiting, next step is to commit. This is how to do it.
|
|
Imaging you forget to add some changes to your last commit or you want to change
commit message of previous commit. Add the new changes to the staging area by
git add
command (if you only want to change the commit message, you can skip
this step), and then amend the previous commit like this.
|
|
To push your local commits to the remote repository
|
|
Similarly, to pull the changes from remote repo to your local copy
|
|
To log all commits
|
|
Find a problem in your new software version? Revert back to old version like this.
|
|
This will revert changes back to the given commit (commit-hash). This will not delete the old faulty commits. Instead, git will create a new commit that cancels off the faulty commits.
Useful references
Note: SO is the abbreviation for StackOverflow
- How to modify a old git commit [SO]
- Upload a local repository to github
- Remove a file from git history
- Delete specific git commit