"Git Commands for Beginners and Pros: A Quick Revision"

Time for a quick git revision! A review for beginners and a quick lookup for pros. Here are the most common, basic Git commands. Configuration Set up your user information for all local repositories. 'git config --global user.name "[Your Name]" ': Sets the name you want attached to your commits. 'git config --global user.email "[your_email@example.com]"': Sets the email you want attached to your commits. Starting a Project Initialize a new repository or clone an existing one. 'git init': Turns the current directory into a new Git repository. 'git clone [url]': Downloads a project and its entire version history from a remote URL (like GitHub). Making Changes (Local) Save your work locally. 'git status': Shows the status of changes: files that are staged, unstaged, and untracked. 'git add [file.txt]': Adds a specific file to the staging area (prepares it for a commit). 'git add . ':Adds all new and modified files in the current directory to the staging area. 'git commit -m "[Your commit message]"': Saves the staged files as a new snapshot in the project's history. The message describes the changes. Viewing History Inspect what has happened in the repository. 'git log': Shows a list of all commits in the repository's history, starting with the most recent. 'git log --oneline': Shows a condensed, one-line view of the "commit history. git diff Shows the differences between your working directory and the last commit (changes that are not yet staged). 'git diff --staged': Shows the differences between your staged files and the last commit. Branching & Merging Work on different features or fixes in isolation. 'git branch': Lists all branches in your local repository. 'git branch [branch-name]': Creates a new branch. 'git checkout [branch-name]': Switches your working directory to the specified branch. 'git checkout -b [new-branch-name]': A shortcut that creates a new branch and switches to it immediately. 'git merge [branch-name]': Combines the history of the specified branch into your current branch. 'git branch -d [branch-name]': Deletes the specified branch (only if it has been merged). Working with Remotes Sync your local repository with a remote one (like GitHub). 'git remote -v': Lists all remote repositories you have configured (shows their URLs). 'git remote add [name] [url]': Adds a new remote repository (e.g., git remote add origin [url]). 'git fetch [remote-name]': Downloads all history from the remote repository but doesn't merge it into your local branch. 'git pull [remote-name] [branch-name]': Fetches changes from the remote and merges them into your current local branch (equivalent to git fetch followed by git merge). 'git push [remote-name] [branch-name]': Uploads your local branch's commits to the remote repository. Hope this helps! What's your most-used Git command? 👇 #git #github #developer #coding #programming #cheatsheet #devops #gitrevision #versioncontrol #developer #softwareengineering #coding

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories