The Main Branch
In Git, the main project is completed on the
main branch. Making your first commit in a new git repository will automatically create a
main branch. Create new branches from the
main branch to develop new features for a project. These branches can be merged into
main at a later time to incorporate the new features. You can use
git branch to check what branch you’re on.
$ git init Initialized empty Git repository in /home/ccuser/new-project/.git/ $ echo "Hello World!" >> hello.txt $ git add hello.txt $ git commit -m 'initial commit' [master (root-commit) bb0e565] initial commit 1 file changed, 1 insertion(+) create mode 100644 hello.txt $ git branch * master
Committing Your Code
git commit -m "log message here" command creates a new commit containing:
- The current contents of the staging area
- A log message describing the changes to the repository
A commit is the last step in our Git workflow. A commit permanently stores changes from the staging area inside the repository. This command is almost always used in conjunction with the
git add command as
git add is used to add files to the staging area.
$ git commit -m "Added About section to README" [master 9d63f80] Added About section to README 1 file changed, 10 insertions(+), 1 deletion(-)
Deleting a Branch
In Git, the
git branch -d branch_name command is used to delete the
branch_name branch. It’s good practice to delete a branch after it has been merged into the
Pull Requests on GitHub
A pull request is a feature of GitHub and other source code management tools that allow a repository’s collaborators to review and give feedback on proposed code changes before they are accepted and merged to another branch, usually the main branch. Each pull request creates a discussion forum that can be used by reviewers and authors alike to highlight or add comments to a single line of code or chunk of code, add videos or images, etc.
Going through the pull request process can increase group knowledge, improve product quality, and develop professional skills through group critique.