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.
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
For more information:
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>