Main Git Commands that are important to know!
-Initialize a Repo
% git init
-Create a Commit
% git add -A
% git commit -m "Title of your snapshot"
-Stage file on at a Time (not using "add -A")
% git add path/to/file1
% git add location/of/file2
% git commit -m "My surgical commit"
-Check your status often
% git status
-See what’s changed with diff
% git diff
-Create a new branch
% git checkout -b fancy-new-version-name
-Switch to a different branch
To list all branches:
% git branch
To switch to another existing branch:
% git checkout branch-name
-See the git log
To see the history of your current branch:
% git log
To see a graph of all your branches at once, try:
% git log --oneline --decorate --graph --all -30
-
Jumpback to a Previous Commit
% git checkout [SHA of commit you want to go back to]
-Push
% git push
The very first time you push to a branch, it may ask you to do something like:
% git push --set-upstream origin your-branch-name
-Start on a new task
Start on a new task
When you’re ready to start on a new task, the best practice is to first switch back to the main branch, get the freshest version, and then to start a new branch from there:
% git checkout main
% git pull
% git checkout -b my-next-task
Top comments (2)
Thank You. I was looking for a git guide and this will be really helpful.
Im happy to help!