Although you can work most changes within GitHub itself, it is highly recommended to get to know how git works by knowing some of most basic git workflow process.
In git workflow, files can be in one of three states:
git add
command if you want to include them in your next commitgit commit
command to put them under git commit history stateThere are Git user interface tools for your desktop like GitHub Desktop or Git Kraken, but you can operate everything out from just git CLI. Here are few commands that are essential to know.
# Pull from the current checked out branch in remote repository
git pull
# change to a branch name that exists
git checkout [branch name]
# Create a new branch from source branch
git checkout -b [new branch name] [source branch]
# Similar to checkout
git switch [branch_name]
# Check for any change
git status
# Add all files that were modified
git add .
# Add files in selective ways
git add file_name1 file_name2
# Restore changed file that was modified
git restore file_name1
# Add files to commit with a message
git commit -m "Some commit message"
# Push committed change to GitHub repo
git push
This diagram shows how a typical git workflow process will happen
Here, we will walk through how these Git commands from your dev machine are used to interact with GitHub
git clone
to clone the project to your local machinegit add
to addd your changes to the staging area
git commit
to take the snapshot of your changesgit push
to upload your changes to GitHubgit fetch
to fetch the latest branches and commits from GitHubgit pull
(a porcelain command of git fetch and git merge) to pull in the latest changes to your branches$ git status
On branch main
Your branch is up-to-date with 'origin/main'.
nothing to commit, working tree clean
git status
is a command to verify the current state of your repository and the files it contains. Right now, we can see that we are on branch main, everything is up-to-date with origin/main and our working tree is clean.
If you type git branch
you will see a list of local branches.
If you want to see all the branches, including the read-only copies of your remote branches, you can add the –all option or just -a.
git branch --all
git branch -a
You can use git log
command to see history of your git commit. But you can also pass additional parameters to see detailed information! One useful command to visualize git is git log --graph --all
. Try it!