2026-08-16 17:07

Status:


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

    • Pasted image 20260816225359.png
      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 init and then add the remote repo after adding in all of your files and staging the first commit of your project

    • Pasted image 20260816225441.png

    • Pasted image 20260816225516.png

    • Pasted image 20260816225552.png

  • 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:

    • Pasted image 20260816225745.png

    • 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 yourDirName to create a new directory inside of wherever you generally are, and then use cd to 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 log or git status respectively, 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 branch which 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 the git 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 status command 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 use git 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 use git push
    • To transfer any of the given changes from a remote repo over to your local repo, you can use git fetch I would assume, it does not merge things on it’s own, but you can do so manually, or use git pull to 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
    • Pasted image 20260816233916.png
    • 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
    • Pasted image 20260816234049.png
    • Pasted image 20260816234124.png
    • 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 -v which gives you the remote repo, and then you can use git 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
    • Pasted image 20260816234633.png
      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
    • Pasted image 20260816234806.png
      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
    • Pasted image 20260816235009.png
      To create a branch and then synchronize your changes, you can generally make a branch with the git branch <newBranch> command, and then git 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
    • Pasted image 20260816235043.png
    • 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
    • Pasted image 20260816235316.png
    • Now, if you want a new developer to join into your collaboration and be able to write code, the would use the git clone feature. 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 clone
      • git pull & git fetch
      • git push
      • git 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
  • 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

TermDefinition
CloningA process of creating a copy of the project’s code and its complete version history from the remote repository on the local machine.
CommitA snapshot of the project’s current state at a specific point in time, along with a description of the changes made.
DeveloperA 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.
ForkA copy of a repository into your GitHub account.
ForkingForking creates a copy of a repository on which one can work without affecting the original repository.
GitHubA web-hosted service for the Git repository.
GitA 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.
IntegratorA role that is responsible for managing changes made by developers.
Main branchA branch that stores the deployable version of your code. The main branch is created by default and is definitive.
MergeA process to combine changes from one branch to another, typically merging a feature branch into the main branch.
OriginA term that refers to the repository where a copy is cloned from.
Pull requestA process used to request that someone review and approve your changes before they become final.
Remote repositoriesRepositories that are stored elsewhere. They can exist on the internet, on your network, or on your local computer.
Repository administratorA role that is responsible for configuring and maintaining access to the repository.
RepositoryA data structure for storing documents, including application source code. It contains the project folders that are set up for version control.
Staging areaAn area where commits can be formatted and reviewed before completing the commit.
UpstreamA term used by developers to refer to the original source where the local copy was cloned from.
Version controlA 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/MethodDescriptionCode Example
git addUsed to move changes from the working directory to the staging areagit add sample.md
git add .Stages all changed files in the current directory and subdirectories for the next commitgit add .
git amUsed to apply patches emailed to the repositorygit am < patchfile.patch
git branchAllows to create an isolated environment within the repository to make changesgit branch
git checkoutAllows to see and change existing branchesgit checkout
git checkout mainAllows to switch to the main branchgit checkout main
git cloneAllows to create a copy of the remote repositorygit clone
git commitAllows you to take staged snapshots of changes and commit them to the project and commit them to the projectgit commit -m “Your commit message here”
git config —global user.emailExample 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 daemonUsed to allow anonymous download from the repositorygit daemon —reuseaddr —verbose
git diffHelps others to review your code to identify and compare the changesgit diff example.txt
git fetchDownloads changes from a remote repository to your local repository without merging themgit fetch
git fetch upstream/mainUsed to grab upstream branchesgit fetch upstream main:upstream-main
git format-patchGenerates or prepares e-mail submission if you adopt Linux kernel-style public forum workflowgit format-patch -n <number_of_commits>
git http-backendProvides a server-side implementation of Git-over-HTTP, allowing both fetch and push servicesgit clone —bare /path/to/repos/myrepo.git
cd myrepo.git
git update-server-info
git initUsed to create a new local Git repository in the specified directorygit init
git instawebAllows to set up web front-end to Git repositoriesgit instaweb -p 8080
git logEnables to browse previous changes to a projectgit log -p filename
git mergeUsed to merge changes from another branch into the current (active) branchgit merge feature_branch
git merge upstream/mainMerges changes from the ‘upstream/main’ branch to the current branchgit merge upstream/main
git pullUsed to transfer the changes from the remote repo to your local repo, and merge them to a branchgit pull origin main
git pull downstreamPulls changes from a downstream repository, specifically from the main branch of that repositorygit pull downstream main
git pull upstreamPulls changes from the “upstream” repository into the current branchgit pull upstream main
git pushUsed to push all the committed changes into the repositorygit push origin your_branch_name
git remoteA command to manage a set of tracked repositoriesgit remote add upstream https://github.com/original/repo.git
git remote add origin Adds a remote repository named “origin” with the specified URLgit remote add origin https://github.com/yourusername/your-repo.git
git remote add upstreamAdds the original repository as a new remote repository labeled upstreamgit remote add upstream https://github.com/original/repo.git
git remote renameThe 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 itgit remote rename origin new-origin
git remote -vAllows to view the remotes associated with the local repositorygit remote -v
git request-pullExample 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 rerereReuses recorded resolution of previously resolved merge conflictsgit rerere
git rerere diff
git resetUndoes changes that were made to the files in your working directorygit reset HEAD~1
git revertUsed to undo botched commitsgit revert HEAD
git send-emailExample 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-shellUsed as a restricted login shell for shared central repository userssudo usermod -s /usr/bin/git-shell gituser
git statusAllows to see the state of your working directory and the staged snapshot of the changesgit status
git versionDisplays the current Git version installed on your systemgit —version