A month or two ago, I wrote an article called How to Get Started with GitHub and Git [FoolProof. If you have no experience with Git or GitHub, I strongly recommend you read it. By the end of that article, you should have a thorough understanding of how to use these tools for your own projects.
In this article, I just want to lay down a quick cheat sheet. It will include commands that I shared in that first article, but it will also include some new git commands. Recently, for various senior projects, I have been collaborating with different teams. There are a few commands that have become a staple for me.
This command is used to initialize a project as a git repository.
Example:
git remote add origin https://github.com/kyledeguzmanx/sample-repo.git
This command is used to add or connect to a remote repository.
This command is used to view connected remote repositories.
This command is used to view the status of files in your local repository. Are files tracked? untracked? modified?
Example:
git add index.html
git add index.html style.css style.scss
This command is used to stage modified or untracked files.
Example:
git commit -m “added navigation bar”
Example:
git push -u origin master
Example:
git rm -r — cached config.js
Example:
git checkout --track origin/develop
Example:
git checkout master
git checkout develop
This command is used to switch to branches you have already visited before.
Example:master branch will inherit code from develop branch
git merge develop
If your merge fails, it will say (master|merging)
or something like that. Maybe it says merge or maybe it’s a forward slash or maybe you’re in another branch. Regardless, you get the idea.
This indicates your merge failed.
git merge --abort
would just abort the merge entirely.
Example:
git merge -X theirs develop
This command will erase all the changes you’ve made in your local repository and update it to the latest version that was committed to GitHub.
This command is used to delete untracked files in your local repository
This command is used to delete untracked directories in your local repository. You can also combine it into git clean -fd
to do both.
Thank you for reading! If you have some commands that you use all the time, please share them!