You can download Git for free from the official Git website: git-scm.com
After intallation, Check if Git is installed or not:
$ git --version
Set the username and mail:
$ git config --global user.name "[USERNAME]"
$ git config --global user.email "[EMAIL]"
Initialize an empty Git repository:
$ git init
Start a demo project and check the status of all project files in your repo
- Untracked [U] refers to new files [created after repo initialization] in the repo
- Changed [M] refers to modified files in the repo
- Added/Staged [A] refers to saved [Untracked & Changed files after add them with git add command] files in the repo.
$ git status
Add/Stage Untracked or Changed files to be a Staged files, add .
to add all files in one time.
$ git add [file.name]
$ git add .
Commit a staged files: Committed files are a save point you can go back to if you find a bug
$ git commit -m "[MESSAGE]"
List all commits for a repository:
$ git log
Create new branch:
$ git branch [BRANCH-NAME]
List all branches
$ git branch
Moving from the current branch, to specific one:
$ git checkout [BRANCH-NAME]
Delete a specific branch:
$ git branch -d [BRANCH-NAME]
Merge current branch with specific branch
$ git merge [BRANCH-NAME]
Go to GitHub and sign up for an account
Remember to use the same e-mail address you used in the Git config.
Create a new repo on GitHub
Push your local repository to GitHub:
$ git remote add origin [GITHUB_REPO_URL]
$ git push -u origin master
Note: Since this is the first time you are connecting to GitHub, you will get some kind of notification to authenticate this connection.
Fetch changes from GitHub repo: To see what has changed on GitHub in this repo:
$ git fetch origin
Merge current branch with remote GitHub branch:
$ git merge origin/[BRANCH-NAME]
Pull [fetch and merge] all changes from a remote repository into the local branch you are working on:
$ git pull origin
Push your changes from local repo to GitHub:
$ git push origin
Branches on GitHub:
List remote branches:
$ git branch -r
Pull Branches:
Create new branch on GitHub and get it local as remote branch:
$ git pull origin
Switching to the local new branch and work on it locally:
$ git checkout [NEW_GITHUB_BRANCH_NAME]
Push a local new Branch to GitHub:
Create a new local branch and push it to GitHub:
$ git checkout -b [BRANCH-NAME]
$ git push origin [BRANCH-NAME]
Now you have a pull request on your GitHub repo you can confirm it and merge it with master branch.
Deploy your website to Github pages:
- Create new github repo
- Push your local repo to the remote one that you just created.
- In your GitHub repo navigate to: [settings] then: [pages]
- If your repo has more than one branch, Select the one that contains your website to deploy it on GitHub pages.
To deploy on the root [USERNAME.github.io]
Create a new repo with specific name [USERNAME.github.io]
then repeat the steps from 2 to 4