DEV Community

Maya Sheriff
Maya Sheriff

Posted on

2

Git Commands

Main Git Commands that are important to know!

-Initialize a Repo

% git init
Enter fullscreen mode Exit fullscreen mode

-Create a Commit

% git add -A
% git commit -m "Title of your snapshot"    
Enter fullscreen mode Exit fullscreen mode

-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"
Enter fullscreen mode Exit fullscreen mode

-Check your status often

% git status
Enter fullscreen mode Exit fullscreen mode

-See what’s changed with diff

% git diff
Enter fullscreen mode Exit fullscreen mode

-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
Enter fullscreen mode Exit fullscreen mode

-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
Enter fullscreen mode Exit fullscreen mode
  • 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
Enter fullscreen mode Exit fullscreen mode

-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
Enter fullscreen mode Exit fullscreen mode

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (2)

Collapse
 
gamecoder profile image
Chitransh Soral

Thank You. I was looking for a git guide and this will be really helpful.

Collapse
 
mayas1111 profile image
Maya Sheriff

Im happy to help!

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs