Github Short Notes
Github Short Notes
WHAT IS GITHUB?
• Git is a DevOps tool used for source code management. It is a free and open-source
version control system used to handle small to very large projects efficiently. Git is used
to tracking changes in the source code, enabling multiple developers to work to
Installation of GitHub
1
2. https://github.com/login
link:: https://git-scm.com/downloads
• git init: This command creates a new Git repository in the current directory. This is the first
step to start tracking changes to your project files with Git.
• git clone: This command is used to clone an existing Git repository from a remote location,
typically a hosting service like GitHub. It creates a local copy of the repository on your
machine.
4
• git branch: This command is used to manage branches in your Git repository. Branches
allow you to work on different versions of your code independently. You can use git branch
to list existing branches, create new branches, and switch between branches.
• git add: This command tells Git which files you want to include in your next commit.
Changes to files that are not added will not be tracked by Git. You can add individual files or
use git add -A or use git add . to add all modified files in the working directory.
• git commit: This command captures a snapshot of the current state of your project. It creates
a new commit object in the Git repository history, along with a commit message that describes
the changes you made.
• git pull: This command is used to fetch the latest changes from a remote repository and
merge them into your local branch. It's a convenient shortcut for combining git fetch (which
downloads the changes) and git merge (which integrates them into your local branch).
• git push: This command is used to upload your local commits to a remote repository. This
allows you to share your changes with other collaborators or keep a backup of your project
online.
5
Now You can upload your file through git bash
7
Topics-5 stages of git
• U (untracked): This indicates that the file is not currently being tracked by Git. It exists
in your working directory, but any changes you make to it won't be included in your
Git commits.
• A (added or staged): This means the file has been added to the staging area, which is
a temporary holding spot for files you plan to include in your next commit. You can
use the git add command to stage files.
• C (committed): This signifies that the file is now part of a Git commit. A commit
creates a permanent snapshot of the state of your project at a specific point in time.
• Purpose: Displays the Git commit history in a concise format, showing only the
abbreviated commit hash and the first line of each commit message on a single line.
• Example:
2. .gitignore
• Purpose: Creates a file named .gitignore in your repository. This file specifies
patterns of files or directories that Git should exclude from tracking. Any changes made
to files matching these patterns won't be reflected in your Git history.
• Example:
8
3. git reset --hard HEAD~1
• Purpose: Moves your working directory (the files you're currently working with) and
the HEAD pointer (which points to the latest commit) one commit back in the Git
history. This effectively discards all changes you've made since the commit you're
resetting to (be very careful with this!).
4. git status -s
• Purpose: Provides a concise summary of the current status of your Git repository. It
shows which files are untracked (U), modified (M), staged (A), or deleted (D).
• Example:
5. git log
• Purpose: Displays the entire Git commit history, including the commit hash, author
name and email, commit date, and commit message for each commit.
• Example:
commit 12a345bfd3b12a...
Author: Alice Smith <[email protected]>
Date: Thu May 23 14:38:20 2024 -0500
commit bcdedf3210abcde...
Author: Bob Jones <[email protected]>
Date: Wed May 22 16:12:55 2024 -0500
• Purpose: Creates a new branch named according to the specified branch name.
Branches allow you to work on independent versions of your codebase simultaneously.
• Example:
7. git branch
• Purpose: Lists all the branches currently existing in your Git repository.
• Example:
9
8. git switch (branch name)
• Purpose: (Also known as git checkout) Switches your working directory to the
specified branch. This changes the files you're currently working with and the HEAD
pointer to reflect the branch you're switching to.
• Example:
9. git merge
• Purpose: Integrates changes from another branch (usually the development branch)
into the current branch (usually the master branch). This allows you to combine work
done on separate branches.
• Example:
10