Git and GitHub
Prakash Pun - December 24, 2022
• 4 min read
Prakash Pun - December 24, 2022
• 4 min read
Git is a free and open-source distributed Version Control System (VCS) designed to efficiently manage everything from small to large projects. It helps developers track changes, collaborate, and maintain a structured workflow.
GitHub is a cloud-based platform built on top of Git that enables developers to host, manage, and collaborate on code repositories.
To begin, download Git from git-scm.com and install it on your system.
Git allows you to set configurations at three levels:
git config --system # System-wide configuration
git config --global # User-specific configuration
git config --local # Repository-specific configuration
To associate your commits with your identity:
git config --global user.name "<your_username>"
git config --global user.email "<your_email>"
git config --global core.editor "atom --wait"
git config --global color.ui true
git config --list
| Command | Description |
|--------------------------------------|----------------------------------------------|
| git init | Initialize Git in your directory |
| git add <filename> | Stage changes before committing |
| git commit -m "<commit message>" | Save changes with a meaningful message |
| Command | Description |
|---------------------------------------|---------------------------------------------------------------|
| git clone <url> | Clone a remote repository into a local workspace |
| git push | Upload local commits to a remote repository |
| git pull | Fetch and merge updates from a remote repository |
| Command | Description |
|---------------------------------------|----------------------------------------------------|
| git branch | List available branches |
| git branch <branch-name> | Create a new branch |
| git branch -d <branch-name> | Delete a branch |
| git branch -D <branch-name> | Force delete a branch |
| git checkout <branch-name> | Switch to a different branch |
| git checkout -b <branch-name> | Create and switch to a new branch |
| git merge <branch-name> | Merge a branch into the current branch |
| git merge --abort | Abort a merge if conflicts occur |
| git log --graph --oneline | View a summarized commit history |
| Command | Description |
|--------------------------------------|----------------------------------------------------|
| git show | View changes in the latest commit |
| git diff | Show differences in unstaged changes |
| git diff --staged | Show differences in staged changes |
| git diff <commit-ID> | Compare differences between commits |
| Command | Description |
|-------------------------------------|--------------------------------------------------|
| git remote | List remote repositories |
| git remote -v | List remote repositories with details |
| git remote show <name> | Display details of a specific remote repository |
| git remote update | Fetch latest updates from the remote repo |
| git fetch | Download objects from a remote repo |
| git branch -r | List remote branches |
| Command | Description |
|-------------------|------------------------------------------------|
| git log -p | View commit history with changes |
| git add -p | Review patches before staging |
| git mv | Move or rename a file |
| git rm | Remove a file from the repository |
If you already have a local repository and want to push it to GitHub:
git remote add origin https://github.com/<your-repo>.git
git branch -M main
git push -u origin main
This command links your local repository to GitHub and uploads your code.
Git is an essential tool for developers and teams, making version control, collaboration, and code management seamless. By mastering these commands, you'll improve your workflow, enhance productivity, and efficiently manage projects.
Keywords: Git commands, GitHub tutorial, version control, Git for beginners, Git commands cheat sheet, Git vs GitHub, Git tutorial for developers.