10 Github Essential commands.

10 Github Essential commands.

What is GitHub?

GitHub is a code hosting platform for collaboration using version control which provide roll back to previous versions of the code. GitHub lets you (and others) work together on projects- sign up for GitHub at github.com: Other platform are Gitlab, Gitbucket etc

GitHub Components are:

1.Repositories 2.Branches 3.Commits 4.Pull Requests 5.Git (the version control software GitHub is built on)6.Commandline

Repository

A GitHub repository can be used to store a development project. It can contain folders and any type of files (HTML, CSS, JavaScript, Documents, Data, Images) should also include a licence file and a README file about the project.

Branch

A GitHub branch is used to work with different versions of a repository at the same time. By default a repository has a master branch (a production branch).

Commits

At GitHub, changes are called commits. Each commit (change) has a description explaining why a change was made.

Untitled7.png

Pull Requests

Pull Requests are the heart of GitHub collaboration. With a pull request you are proposing that your changes should be merged (pulled in) with the master. Pull requests show content differences, changes, additions, and subtractions in colors (green and red).

Git

The most popular VCS Version Control System (at least among web developers) is Git. To use Git, developers use specific commands to copy, create, change, and combine code. These commands can be executed directly from the command line or by using an application like GitHub Desktop or Git Kraken. Here are some common commands for using Git:

**NOTE:Commandline/Vs Code on Window not Commandline on Mac/Linux

HOW TO:

  • change to diff. directory => chdir "C:\Users\kolex\Documents\davidrepo
  • create Directory => mkdir "C:\Users\kolex\Documents\davidrepo OR mkdir davidrepo
  • To create file inside a directory => cd. >index.html OR code index.html
  • listing all files in a directory => dir
  • listing all directory content => $ dir C:\windows
  • home directory => C:\Users\kolex
  • check what directory=> cd
  • navigate relative directory =>C:\
  • to clear screen => cls
  • navigate 1 directory up => cd..

github 2.png

1.How to create Directory/Folders on commandline/Vs-terminal

-mkdir "C:\Users\kolex\Documents\davidrepo OR VsCode mkdir davidrepo -cd "C:\Users\kolex\Documents\davidrepo -you can add files into it -cd. >index.html -cd. >home.html

2.How to create files & folders on commandline/Vs-terminal

a)To create file inside a directory cd. >index.html

b)To create folder inside a directory md images

c)To list all files & folders dir Desktop\david repo

3a.How to create repository on github

-open your github account -click + and select New repository -enter repository name (only) -click create repository

create-new-repo.png

3b.create a new repository on the command line

echo "# Tribute-page-project" >> README.md git init git add README.md git commit -m "first commit" git remote add origin github.com/buquio/Tribute-page-project.git git push -u origin master

**Before you go further check this meanings:

Basic Git commands

**git init - initializes a brand new Git repository and begins tracking an existing directory. It adds a hidden subfolder within the existing directory that houses the internal data structure required for version control.

**git clone - creates a local copy of a project that already exists remotely. The clone includes all the project’s files, history, and branches.

**git add - stages a change. Git tracks changes to a developer’s codebase. Staging and committing separately gives developers complete control over the history of their project without changing how they code and work.

Untitled4.png

**git commit - saves the snapshot to the project history and completes the change-tracking process. In short, a commit functions like taking a photo. Anything that’s been staged with git add will become a part of the snapshot with git commit.

**git status - shows the status of changes as untracked, modified, or staged.

**git branch- shows the branches being worked on locally.

**git merge - merges lines of development together. This command is typically used to combine changes made on two distinct branches. For example, a developer would merge when they want to combine changes from a feature branch into the main branch for deployment.

**git pull - updates the local line of development with updates from its remote counterpart. Developers use this command if a teammate has made commits to a branch on a remote, and they would like to reflect those changes in their local environment.

**git push - updates the remote repository with any commits made locally to a branch

4a.Adding existsing directory to new repository

-open existing directory e.g cd "C:\users\okosisi\document\davidrepo -do git init -create & open new repository on github -copy the url from the repository -git remote add origin + url
-do git add . -do git status -do git commit -m "we are here" -do git push -or git push -u origin master -or git push --set-upstream origin master

4b.Adding existing directory to new repository on github- Method 2

-create a new repository + readme file -open the repository -click upload files -copy the local directory/files -paste it inside the space of upload files on github -add commit message -check/tick master branch -click commit changes -go to command line -git remote add origin github.com/buquio/Tribute-page-project.git -git push -u origin master -or git push --set -upstream origin master

5.Clonining/Copying Repository to local machine.

-open the respository on github -click and copy the url -navigate to the new receiving directory -type git clone + url -do ls to see the file inside -do cd to see inside the folder -git add .

5b.Fetching changes from repository into local directory

-do git pull -or git fetch + git merge

5c.Pushing changes on local to Repository

-git push -or git push--set-upstream origin master(for the first time)

6.Forking Repository from another account

-open another person's github account using their url -then click fork.

7.How to create branches

-open a repository -click create new branch -type branch name e.g sample branch -u can do pull request or compare -make changes to any file -commit changes to sample branch -or do pull request to master branch

8.How to create branches

-git branch [branch name] or git branch -b "sample-branch" //(Creates a new branch) -git checkout [branch-name] or git checkout "sample-branch" //(switches you into the branch) -Make the desire changes -Add and commit changes -git add . -git status -git push-u [origin][branch]

9.How to create pull request on a.branches b.forking c.project

a.branches -click and select the branch you want to... -click pull request -click create pull request -rename the title -add comment -click create pull request or click pull request -click file changes & preview *you can preview if u are the contributor (+) -click merge pull request -click confirm merge

pull request.png

9b.forking a repository

-create a new pull request inside nina-text github -click the latest commit to see -go to the pull request-1 -move to the right & click on pull request -click on new pull request & click on create pull request & put title e.g nina pull request -write comment -click create pull request

9c.Merging pull request e.g to merge pull request from nina account to btholt project

-go to btholt account -click on btholt top right -click repository -click pull request(on list) -click pull request (20)(on list) -click any of the pull request or the nina pull request -click tab-conversation -then go down left & click merge-pull request -then click "confirm pull request" -then click ......../pull request(top left) -then you will see READ.md & mark.txt -u can accept more pull request -u can comment on each line of code at tab- file change.

merge pullrequest.png

10.ignoring files and folders

-Navigate to the location of your Git repository. -Create a .gitignore file for your repository eg .gitignore -to ignore a file that is already checked in, you must untrack the file locally using git rm -r --cached FILENAME -then list all the files/folder you want to ignore inside .gitignore

  • add file like this:*.txt
  • add folder like this:/[Ll]ibrary/ -git commit -m "Removed folder from repository" -git push origin master

You can completely remove using:git rm --cached FILENAME you can completely restore using:git restore --staged FILENAMEs

10b to ignore the whole project folder

-git config --global core.excludesfile ~/.gitignore_global

10c To ignore an entire directory in Git, the easiest way is to include a . gitignore file within the target directory which simply contains "". dirB/. gitignore then just reads as “” and all contents are ignored completely, itself and all files.

for reference git-scm.com/docs guides.github.com/features/pages

Don't forget to comment below and show your support by liking this article and follow me on Twitter

PS: this is my first article on HashNode