Site icon Java Guidance

Git: the basic commands every developer should know

In this blog, We are going to discuss basic git commands :

1. git init
This command will create a new Git repository in the current directory and it will create a `.git` folder where version control information is stored.

2. git clone <repository>
This command will create a local copy of a remote repository and it fetches all files and commits from the specified repository URL.

3. git add <file>
This command will stages changes made to a file for the next commit. We can add multiple files or use `.` to stage all changes in the directory.

4. git commit -m “message”
This command will records the staged changes to the repository with a descriptive message. Commits are snapshots of your project’s history.

5. git status
This command will displays the current state of the working directory and staging area. It shows modified, staged, and untracked files.

6. git pull
This command will create a fetches and merges changes from the remote repository into the current branch. It’s a convenient way to keep your local branch up to date.

7. git push
This command will create a sends your committed changes to a remote repository. This updates the remote branch with your local commits.

8. git branch
This command will lists all branches in the repository. You can also create a new branch using `git branch <branch-name>`.

9. git checkout <branch>
This command will create a switches to a specified branch in your repository. You can also use it to create a new branch with `-b`.

10. git merge <branch>
This command will create a combines changes from the specified branch into the current branch. It integrates work from different branches.

11. git log
This command will displays a chronological history of commits in the repository. It includes commit IDs, authors, dates, and messages.

12. git reset <file>
This command will instages a file, reverting it back to the last committed state. This command is useful for correcting mistakes before committing.

Exit mobile version