GitHub is a platform that allows developers to store their code in the cloud and collaborate. Git is a version control system that tracks file changes. In this article, we will focus on using Git with GitHub.
Create a new Git repository
git init
Display the status of the working directory
git status
Create an empty file in your root directory. Tell Git which files or folders to ignore in your project
touch .gitignore
To stage all files
git add .
To stage a specific file
git add [filename]
To stage a folder use
git add [folderpath]
Add all tracked files and the commit them with your message
git commit -m “first commit”
Rename the master branch to main
git branch -M main
Add a remote repository
git remote add origin <remote_repository_URL>
Replace ‘<remote_repository_URL>’ with the URL of your remote repository.
For example:
git remote add origin https://github.com/username/repository.git
Push the changes to the remote repository
git push -u origin main
git remote set-url origin https://<token>@github.com/<username>/<repo>
For information about personal access tokens:
Run the following to give you the git version number
git --version
Find out the current branch name
git branch
Track a branch’s commit history
git log
Verify the remote url
git remote -v
Copies an existing Git repository
git clone https://github.com/username/repository.git
Switch branches
git checkout <branch>
To revert changes to match a specific commit,
git reset --hard <some-commit>
git push --force
Check your configuration settings
git config --list
Configure Git. Let Git know who you are
git config --global user.name “<username>”
git config --global user.email “<email>”
See all possible commands
git help --all
Sign up for an account on GitHub:
https://github.com
For more information: