Handy Git Commands

Posted by Paul on October 21, 2021

Just a little page for some handy git commands (these may not be totally accurate yet, this is a work in progress):

Add the current folder to git:
git init

Link it to a remote repository which will become the origin:
git remote add origin https://github.com/user/repo

Check what the remote repo is:
get remote -v

Add everything in the folder to be tracked:
git add .

Commit changes locally as a version:
git commit -m "Descriptive message."

Push changes to the remote origin:
git push -u origin master

Workflow for Pushing Files to a Remote Origin
Your files start in a local folder called the Working Directory.
git init makes this a git folder.
git add adds them to an area called the Staging Area.
git commit adds them to an area called the Local Repo (HEAD).
git push adds them to the Remote Repo (MASTER).

Workflow for Pulling (Potentially Changed) Files from a Remote Origin
Someone might have made changes to the Remote Repo.
git fetch gets changes from the Remote Repo to the Local Repo.
git merge helps you merge from the Local Repo to the Working Directory.
git pull attempts to do the above 2 steps automatically in 1 command.

More info:

blog comments powered by Disqus