GitHub
GitHub is a popular online platform that hosts and manages software development projects using Git, a version control system. It provides a collaborative environment for developers to work together on projects, track changes, and collaborate on code.
Creating an account on Github
Go to GitHub and sign up for an account:
or
If you already have an account login your github into browser and create a repository, we have already set up a local Git repo, we are going to push that to GitHub:
Note: Remember to use the same e-mail address you used in the Git config.
Creating a repo in github
You have made a GitHub account, sign in, and create a new Repo:
Enter name of the repository
Push Local Repository to GitHub
Copy the URL, or click the clipboard marked in the image above.
Now paste it the following command:
git remote add origin (link copied above)
git remote add origin url specifies that specifies that you are adding a remote repository, with the specified URL, as an origin to your local Git repo.
Now we are going to push our master branch to the origin url, and set it as the default remote branch:
git push –set-upstream origin master
Note: Since this is the first time you are connecting to GitHub, you have to connect your github account to git using personal access token, which you would create in github.
After this command you need to refresh your github page and you will see your files you created in git inside your git repo.
Repository
A repository (often abbreviated as “repo”) in Git is a storage space where your project’s code, files, and the entire version history (commits, branches, etc.) are stored. Repositories allow developers to track changes in code over time and collaborate with others.
Types of Repositories in Git:
1. Local Repository
- A local repository is the version of the Git repository that exists on your local machine (your computer). It contains all your project’s files and the Git history (commits, branches, tags) for that project.
- Workflow: You create and manage the local repository using Git commands, making changes to files, committing those changes, and creating branches.
- Key Commands:
- Create a local repo:
git init - Check the status of a local repository:
git status - View the history of commits:
git log
2. Remote Repository
- A remote repository is a version of your repository hosted on a server, typically accessed via the internet (for example, hosted on GitHub, GitLab, Bitbucket, etc.). Remote repositories are used for collaboration with others.
- Workflow: A remote repository is often a shared or central repository that team members push to and pull from. Developers clone this repo to their local machines, make changes, and then push their changes back to the remote repo.
- Key Commands:
- Add a remote repository:
git remote add origin https://github.com/user/repo.git - Push changes to a remote repo:
git push origin branch-name - Pull changes from a remote repo:
git pull origin branch-name
3. Bare Repository
- A bare repository is a special type of Git repository that does not contain a working directory (the actual project files) but only the .git folder (the version history and metadata). It is typically used as a central repository for collaboration, especially when setting up a remote repository on a server.
- Workflow: In contrast to a normal repository, you cannot edit files directly in a bare repository. It is intended to serve as a storage location for other developers to push their changes to and pull from.
- Common Use Case: When you host your own remote Git repository (not on services like GitHub or GitLab), you use a bare repository. GitHub itself stores repositories as bare repositories.
- Key Command:
- Create a bare repository:
git init – -bare
4. Cloned Repository
- A cloned repository is a local copy of a remote repository. When you clone a repository, you download all the files and the Git history from the remote server to your local machine.
- Workflow: Developers clone a remote repository to their local machines to contribute to a project. Once cloned, they can work on the local copy, make changes, and later push the changes back to the remote repository.
- Key Command:
Clone a repository:
git clone https://github.com/user/repo.git
5. Forked Repository (GitHub-specific concept)
- A fork is a copy of another user’s repository on GitHub or similar platforms. When you fork a repository, you create a copy of it under your own GitHub account.
- Workflow: Forking is often used in open-source development. You fork a project to your own account, make changes, and submit those changes back to the original project through a pull request.
- Key Steps:
- Fork a repository on GitHub (button on the GitHub UI).
- Clone your fork to your local machine:
git clone https://github.com/your-username/forked-repo.git
6. Mirror Repository
- A mirror repository is a repository that is a replica of another repository. It’s used when you need to maintain an exact duplicate of another repository, including all refs (branches, tags, etc.).
- Common Use Case: Mirroring is often used for backup purposes or for maintaining synchronised copies of repositories across different Git servers.
- Key Command:
- Mirror a repository:
git clone –mirror https://github.com/user/repo.git
Visit Git tutorial –Click Here