DEV Community

juved
juved

Posted on

STARTING WITH GITHUB

GitHub

GitHub is a cloud based service for version control and software development, and very popular in data science and various fields. It allows real-time collaboration, it encourages teams to work together, giving them confidence in managing changes and version control.

*Git and GitHub *
Git, was created in 2005 by Linus Torvalds, is an open source version control system. Allowing each team member to work using a branch. GitHub is using Git as version control system.

Work Flow understanding

GitHub wokflow understanding by JE,@juved

REPOSITORY
A repository, or repo in GitHub, is a storage location containing all project files including codes, images, documents, and revision history. It serves as the central location where the team can contribute to the project under their branches.
In GitHub, there are two types of repositories:

  • Public Repositories: They are visible and accessible to anyone online, and the content can be cloned. They are offered for free by GitHub to facilitate collaboration on open-source projects.

  • Private Repositories: They are visible only for the repository owner and team. Regarding access control, the owner can invite a team member to collaborate on a private repository. GitHub charges for privates repositories as part of its subscription.

BRANCHE

It is a parallel repository where everyone or team member can work isolated without affecting the main/master branches.

Here are some common git commands:
-- git branch < branch_name> # to create a new branch
--git checkout < branch_name> # to switch to a branch
--git switch < branch_name># to switch to a branch
--git checkout -b < branch_name> # to create and switch to a new branch
--git branch # will list all branches
--git merge # to merge a branch into the current branch
--git branch -d < branch_name> #delete a local branch
--git push origin --delete < branch_name> delete a remote branch
--git push origin < branch_name> #push a local branch to a remote
--git push -f origin < branch_name> # force pushing a branch to remote (with caution)
--git branch - m < branch_name > # to rename a branch
--git branch -v # to view the last commit on each branch
--git diff < branch_name1>.. < branch_name2># to compare changes between branches
--git merge --abort # to abort a merge
-- git branch - r # to list remote branches

More commands in GitHub:

Git status : with this command, we provide the state of the working directory and the staging area. It is recommended to use if often to check your directory.
--git status

Create a new repository, but avoid creating a directory inside another one.
-- git init

Clone a directory : to download an existent repository to your local location. You'll be able to work locally on the project documents
--git clone

Git add, after working, modifying files in the directory. Git add command help in staging the files.
-- git add

Commits, after staging the files with git add, git commit will save the changes. A message describing the changes is recommended.
-- git commit -m “example message”

Git push is moving your changes locally to the remote repository
--git push origin

Fetching and Merging
It is the process of retrieving all the changes from the remote repository without merging them to the local repository or your working repository.

-- git fetch origin master
--git fetch upstream

Pull

Git pull is used to basically to update your local repository with changes mad by team members on the remote repository. It combines two commands: git fetch and git merge.

Pull request

allow a team member to propose changes to a repository.It's a way to notify other teams members about changes that you have pushed to a branch in a repository.

*Avoiding doing *

  • Push sensitive information
    It is recommended to avoid pushing sensitive information like passwords, privates files to a public repository. Use .gitignore file to exclude them

  • Force Pushing to a Shared Branch
    Be careful with forcing push, particularly to branches of others. This can cause confusions and overwrite their changes.

  • Inconsistent Branch Naming
    Maintain a consistent branch naming is a must. It will make it easier for collaborators to understand the purpose of the branch.

  • Ignoring Pull request and issues
    Not regularly Updating Forks
    In the case you fork a repository, maintaining a regular synchronization with the upstream is important to make sure you integrate the changes made by the collaborators.

Git documentation https://git-scm.com/docs

Alternatives to GitHub: GitLab, GitKraken, Beanstalk, Gitea, RhodeCode, SourceForge

Top comments (0)