Git and GitHub are essential tools for software development. In this project, we’ll be creating a simulation of a one-year experience in a company that uses Git and GitHub. We’ll start with a beginner-level understanding of Git and GitHub and gradually work our way to an expert-level understanding.
Step 1: Initializing a Git Repository
git init
This command creates a new Git repository in the current directory.
Step 2: Creating a GitHub Repository
$ git remote add origin https://github.com/<username>/<repository>.git
$ git push -u origin master
Step 3: Making Changes and Committing
$ git add .
$ git commit -m "Initial commit"
The git add
command stages the changes, and the git commit
command creates a new commit with a message.
Step 4: Branching
$ git checkout -b feature1
Step 5: Merging
master
).feature1
branch into master
:$ git checkout master
$ git merge feature1
tep 6: Pull Requests
Pull Requests
tab. Then, click on the New Pull Request
button.Step 7: Tagging
$ git tag v1.0
This creates a new tag named v1.0
at the current commit.
Step 8: Collaborating with Others
Fork
button. This creates a copy of the repository in your own account.$ git clone https://github.com/<username>/<repository>.git
This creates a local
Copy of the repository on your computer, allowing you to work on it locally and make changes.
Step 9: Managing Conflicts
Conflicts can arise when multiple people make changes to the same file in a project. Git helps manage these conflicts by marking them in the file and requiring you to resolve them manually.
To resolve a conflict, open the file in question and look for the conflict markers (<<<<<<<, =======, >>>>>>>).
Edit the file to resolve the conflict, then run the following commands to stage and commit
the changes:
$ git add <file>
$ git commit -m "Resolved conflict in <file>"
Step 10: Advanced Git Commands
As you become more experienced with Git and GitHub, you may want to learn more advanced Git commands to further improve your workflow. Some examples include:
git stash: Temporarily saves changes that have not yet been staged.
git rebase: Re-applies a series of commits on top of a different base branch.
git cherry-pick: Applies a specific commit from one branch to another.