git-image
General

10 Common Git Commands You Should Know

Date Published

Git is an essential tool for developers and anyone working on version-controlled projects.  

Here are 10 common Git commands to get you started:


1. git init


Initialize a new Git repository in your project directory.


1git init


2. git clone


Clone an existing repository from a remote source (e.g., GitHub).


1git clone <repository_url>


3. git add


Stage changes (files or folders) for the next commit.


1git add <file_or_folder>


To stage all changes:


1git add .


4. git commit


Record staged changes to the repository with a descriptive message.


1git commit -m "Your commit message here"


5. git status


View the current status of your repository, including staged, unstaged, and untracked changes.


1git status


6. git log


Display a history of commits in the repository.


1git log


For a one-line summary:


1git log --oneline


7. git branch


List, create, or delete branches.


To list branches:


1git branch


To create a new branch:


1git branch <branch_name>


8. git checkout


Switch to a different branch or restore files.


To switch branches:


1git checkout <branch_name>


To create and switch to a new branch:


1git checkout -b <branch_name>


9. git merge


Combine changes from another branch into the current branch.


1git merge <branch_name>


10. git push


Upload your local commits to a remote repository.


1git push <remote_name> <branch_name>


To push all branches:


1git push --all




Bonus: git pull


Fetch and merge changes from a remote repository.


1git pull <remote_name> <branch_name>




Master these commands to work effectively with Git and manage your projects like a pro!

Related Posts:

10 Common and essential Git Commands You Should now about | Payload Website Template