2026-08-16 17:07
Status:
Tags: Git Github Version Control Tools Programming Programming Concepts Command Line IBM Full Stack Software Developer Professional Certificate IBM IBM - Getting Started with Git and Github
IBM - GSGG - Git Commands and Managing GitHub projects
==Git Workflows with Git Commands
-
Overview of Git Workflows:
-
An understanding of git workflows makes sure that you can use git comprehensively and easily in collaboration, allowing to avoid things like code conflict and overwriting someone else’s work
-
The first step is cloning a repository from the organization on github, this means downloading it on your local machine.
-
The said then connection allows you to push and pull changes to and from the remote repository, so they can be updated and up to date.
-
You, as a developer, want to work on the code and so you do this to update the code in the repository
-
You can create a branch in order to not have the code that you are writing affect the main branch of code until your given feature is necessary
-
You then want to stage the files, and commit them, you basically move the completed files into the repo, and then you can commit them over to the new branch of code, committing changes lets you record changes and add context to the change you made
-
You then want to push the changes to the remote repository and basically have someone review your code and make sure that the repository branch that you have made is well documented and reviewed before it is actually merged inside of the main repository
-
This is basically done via a pull request where someone has to review over your code before it is accepted from your branch and merged into the main
-
When starting a local project that you want to share you can initialize a local git repository in your current start up code and then toss it over into the remote site so anyone can access -
You generally run something like
git initand then add the remote repo after adding in all of your files and staging the first commit of your project -
-
-
-
-
Overview of Git Commands:
-
Git Commands are used for a ton of stuff, like tracking and saving changes, and sharing said changes with others
-
Generally these things would be done via the user interface, but it can also be done through a CLI
-
Some common and useful commands in image below:
-
-
If, as a dev say you want to add a new HTML file to the site to play around and experiment, but do not wish to disrupt the actual main code
-
You would use a
mkdir yourDirNameto create a new directory inside of wherever you generally are, and then usecdto get into that place -
You create a new repo inside of there with
git init, which sets up the needed things for git to start it’s version control -
you create a new html file and add it to git via
git add index.html, and now it is in the staging area -
This lets you commit it with something like
git commit -m "Your Message" -
You can then view your commit history or the status of your current commit using
git logorgit statusrespectively, this can also let you view different and previous commits as well -
If you want to experiment with the code but not touch the main branch, you can use something like
git branchwhich by itself shows you a list of what the current branch is, but can also do more -
To create a branch you use
git branch <yourNewBranch>, and then to navigate over to it you use thegit checkout <yourNewBranch>and then you can then do the same steps above to basically commit new work to the new branch -
You can now view different things with the
git log & git statuscommand and all other such things basically -
When you are ready to merge, you can use the
git merge <yourNewBranch>command in order to merge the feature branch into the main branch of code
-
-
Reading: Git Commands:
-
Cloning and Forking Github Projects:
- Github has a LARGE number of different repositories and a lot of them can be very useful, this makes forking & cloning some of the most powerful tools in git
- Cloning creates a copy of a repository on your local machine, and cloned copies can be kept in sync between the two locations
- Forking allows you to modify or extend a project without affecting the original project, generally used to take a project and use it as a foundation for your new project
- To clone a git hub repo, you want to find the repo you want to copy, find the code button, and then basically copy that link. You can then go to whatever directory you want in the CLI and use
git clone <thatURL>to copy the folder. You can also usegit clone <thatURL> .in order to copy the contents not into a new directory but directly the one that you are in - You can also directly download the source code of whatever you are cloning, but without the actual github repo stuff in it
- You can then sync the code back to github with:
git add <files>,git commit -m <yourmessage>and then usegit push - To transfer any of the given changes from a remote repo over to your local repo, you can use
git fetchI would assume, it does not merge things on it’s own, but you can do so manually, or usegit pullto have it merge automatically - Origin generally refers to your fork, and upstream generally refers to the original work, but they can generally be named whatever you would like of course
- Forking a Project forking takes a copy of a github repository to use it as the base for a new project
- You can also use forking to submit changes back to the original repository, which can be used to independenly make changes to a project
- You can do so by making a pull request to the original project owner so they can decide if they want to accept your changes
- You can also keep a copy of the license file which is generally a common practice for legal issues, it is basically just good practice
- To sync a fork, you create a local clone of the project, you then change to the directory containing a fork through the terminal, you then type in
git remote -vwhich gives you the remote repo, and then you can usegit remote add upstream <clone directory>to basically try and sync up the whole thing
-
Cloning Versus Forking:
- Github allows for multiple different developers to work on their projects and repositories in parallel
- A project resides as either a public or private repository, and each dev might have a different local copy of that repo on their computer, which is the local repo, and the one on the internet is the remote repo
- When to Fork? basically you want to fork something when you want to try and sort of transform the project and try to add in new features and have a new derivative of the older project
- You basically do this so you can develop on top of the existing codebase and you do not need to start from scratch. It basically is good whenever you want to use someone else’s code as your general starting point
Forking is only available via the github web user interface, and there is no native command for creating a fork via the terminal- The repo from which you create the fork is known as the original upstream repository
- Therefore, once you fork the original upstream, the forked copy then becomes the origin, and people can then clone the origin into a local repo and develop from it
THIS ONLY WORKS IF YOU ALREADY HAVE COMMIT PERMISSIONS- If you do not, then you need to use something called a pull request which allows for the maintainers of the code to review the changes, provide feedback, and then merge the code that you had committed
To create a branch and then synchronize your changes, you can generally make a branch with thegit branch <newBranch>command, and thengit checkout <newBranch>to switch over to it- Once the changes are made you can save and stage them, committing them. Once these changes are all good
- You can then push the changes to new branch generally called the upstream branch, you can then raise a request to the maintainer to merge new branch to main branch
- The above hand is a review of the fork workflow that is described in greater detail in the above notes, good diagram though can not lie
- Now, if you want a new developer to join into your collaboration and be able to write code, the would use the
git clonefeature. This lets them clone the repository over and it’s commit changes and history too. At which point they can create a new branch and then try and start adding in new features for later on merges and pull requests - See the note section above this one for more information on cloning repositories and their properties
-
Managing Github Projects:
- There are multiple roles that are needed in actually managing the github project, including things like:
- Developer
- Integrator
- Repository Administrator
- A developer porting as a participant inside of a given project communicates with others using these commands:
git clonegit pull & git fetchgit pushgit request-pull
- These developers, when working from a local personal workstation, can also generally use installed git applications that allow them to perform these actions using a User Interface
- A Github Integrator is an integrator that basically receives changes made by others and reviews and integrates them into the main code
- They would be the ones that review and respond to pull requests, and choose the things that get published for others to use
- They would use the following commands
git pull(merge from trusted lieutenants)git revert(undo any botched commits)git push(publish the project)
- The Repository Administrator basically structures the repository and decides the way that it is organized. This means that they are the ones that establish how a user would interact with a repository, and manage communities, asset types, relationship, categories, and attributes
- They set set up and maintain access for the devs and integrator
- They also configure the servers needed for accessing the web servers and documentation needed for a given project, defining also things like email and index settings, and how an application would look and feel
- They would also use Github Actions to automate software workflows which is basically CI/CD or continuous integration and continuous development
- There are multiple roles that are needed in actually managing the github project, including things like:
-
Summary: Git Workflows with Git Commands:
- GitHub has over 100 million repositories. You can clone a repository and sync changes back to the original. You can also fork a repository and use it as the base for the new project or work on that project independently.
- The steps included in a GitHub workflow are:
- Clone the remote repository or initialize a Git repository.
- Move files to a staging area.
- Perform an initial commit.
- Create a branch and work on it.
- Add files to the staging area and commit.
- Push local commits to the remote repository.
- Create a pull request for review and merging.
- Use the pull operation to update the local repository.
- Multiple roles are involved in managing a project: Developer, Integrator, and Repository Administrator.
- A Developer working in a group project uses commands like git clone, git pull, git fetch, git push, and git request-pull in addition to the ones needed by a standalone developer.
- An Integrator in a group project reviews and integrates changes made by others. Integrators use commands like git pull, git revert, and git push in addition to the ones needed by participants.
- Repository Administrators structure how the repository is organized and how users interact with the repository. They also configure the servers needed for accessing the web services and documentation, define email and index settings, and manage the look and feel of the application.
==Glossary
| Term | Definition |
|---|---|
| Cloning | A process of creating a copy of the project’s code and its complete version history from the remote repository on the local machine. |
| Commit | A snapshot of the project’s current state at a specific point in time, along with a description of the changes made. |
| Developer | A computer programmer who is responsible for writing code. |
| Distributed version control system (DVCS) | A system that keeps track of changes to code, regardless of where it is stored. Multiple users work on the same codebase or repository, mirroring the codebase on their computers if needed, while the distributed version control software helps manage synchronization amongst the various codebase mirrors. |
| Fork | A copy of a repository into your GitHub account. |
| Forking | Forking creates a copy of a repository on which one can work without affecting the original repository. |
| GitHub | A web-hosted service for the Git repository. |
| Git | A free and open-source software distributed under the GNU General Public License. It is a distributed version control system that allows users to have a copy of their own project on their computer anywhere in the world. |
| Integrator | A role that is responsible for managing changes made by developers. |
| Main branch | A branch that stores the deployable version of your code. The main branch is created by default and is definitive. |
| Merge | A process to combine changes from one branch to another, typically merging a feature branch into the main branch. |
| Origin | A term that refers to the repository where a copy is cloned from. |
| Pull request | A process used to request that someone review and approve your changes before they become final. |
| Remote repositories | Repositories that are stored elsewhere. They can exist on the internet, on your network, or on your local computer. |
| Repository administrator | A role that is responsible for configuring and maintaining access to the repository. |
| Repository | A data structure for storing documents, including application source code. It contains the project folders that are set up for version control. |
| Staging area | An area where commits can be formatted and reviewed before completing the commit. |
| Upstream | A term used by developers to refer to the original source where the local copy was cloned from. |
| Version control | A system that allows you to keep track of changes to your documents. This process allows you to recover older versions of the documents if any mistakes are made. |
References
| Package/Method | Description | Code Example |
|---|---|---|
| git add | Used to move changes from the working directory to the staging area | git add sample.md |
| git add . | Stages all changed files in the current directory and subdirectories for the next commit | git add . |
| git am | Used to apply patches emailed to the repository | git am < patchfile.patch |
| git branch | Allows to create an isolated environment within the repository to make changes | git branch |
| git checkout | Allows to see and change existing branches | git checkout |
| git checkout main | Allows to switch to the main branch | git checkout main |
| git clone | Allows to create a copy of the remote repository | git clone |
| git commit | Allows you to take staged snapshots of changes and commit them to the project and commit them to the project | git commit -m “Your commit message here” |
| git config —global user.email | Example 1: Sets a global email configuration for Git Example 2: Sets a global username configuration for Git | Example 1: git config —global user.email “[email protected]” Example 2: git config —global user.name “Your Name” |
| git daemon | Used to allow anonymous download from the repository | git daemon —reuseaddr —verbose |
| git diff | Helps others to review your code to identify and compare the changes | git diff example.txt |
| git fetch | Downloads changes from a remote repository to your local repository without merging them | git fetch |
| git fetch upstream/main | Used to grab upstream branches | git fetch upstream main:upstream-main |
| git format-patch | Generates or prepares e-mail submission if you adopt Linux kernel-style public forum workflow | git format-patch -n <number_of_commits> |
| git http-backend | Provides a server-side implementation of Git-over-HTTP, allowing both fetch and push services | git clone —bare /path/to/repos/myrepo.git cd myrepo.git git update-server-info |
| git init | Used to create a new local Git repository in the specified directory | git init |
| git instaweb | Allows to set up web front-end to Git repositories | git instaweb -p 8080 |
| git log | Enables to browse previous changes to a project | git log -p filename |
| git merge | Used to merge changes from another branch into the current (active) branch | git merge feature_branch |
| git merge upstream/main | Merges changes from the ‘upstream/main’ branch to the current branch | git merge upstream/main |
| git pull | Used to transfer the changes from the remote repo to your local repo, and merge them to a branch | git pull origin main |
| git pull downstream | Pulls changes from a downstream repository, specifically from the main branch of that repository | git pull downstream main |
| git pull upstream | Pulls changes from the “upstream” repository into the current branch | git pull upstream main |
| git push | Used to push all the committed changes into the repository | git push origin your_branch_name |
| git remote | A command to manage a set of tracked repositories | git remote add upstream https://github.com/original/repo.git |
| git remote add origin | Adds a remote repository named “origin” with the specified URL | git remote add origin https://github.com/yourusername/your-repo.git |
| git remote add upstream | Adds the original repository as a new remote repository labeled upstream | git remote add upstream https://github.com/original/repo.git |
| git remote rename | The git remote rename command is followed by the name of the remote repository(origin) you want to rename and the new name(upstream) you want to give it | git remote rename origin new-origin |
| git remote -v | Allows to view the remotes associated with the local repository | git remote -v |
| git request-pull | Example 1: Creates a summary of changes for your upstream to pull Example 2: Generates a summary of pending changes for an email request | Example 1: git request-pull origin/main your-branch Example 2: git request-pull |
| git rerere | Reuses recorded resolution of previously resolved merge conflicts | git rerere git rerere diff |
| git reset | Undoes changes that were made to the files in your working directory | git reset HEAD~1 |
| git revert | Used to undo botched commits | git revert HEAD |
| git send-email | Example 1: Sends your email submission without corruption by your MUA Example 2: Sends a collection of patches as emails | Example 1: git send-email —to=[email protected] path/to/patchfile.patch Example 2: git send-email —to [email protected] patches/*.patch |
| git-shell | Used as a restricted login shell for shared central repository users | sudo usermod -s /usr/bin/git-shell gituser |
| git status | Allows to see the state of your working directory and the staged snapshot of the changes | git status |
| git version | Displays the current Git version installed on your system | git —version |












