Git Commands

Git Commands

A quick guide - to keep handy

Introduction

Git is a powerful version control system that allows developers (and professionals who might benefit from the tool) to track changes, collaborate on projects, and manage code efficiently (you can learn more about version control here). In this post, we will cover a few of the most frequently used Git commands (at least the ones I use most often in development) and outline their basic functionalities.

List of Git commands

git init

The git init command initializes a new Git repository in your current working directory. It creates a hidden “.git” folder that contains the necessary data for version control.

git clone [repository_url]

The git clone command allows you to copy an existing Git repository from a remote source, such as GitHub. It downloads the entire repository, including its history, to your local machine.

git add [file(s)]

The git add command stages file(s) for the next commit. You can specify individual files or directories. Use git add . , to stage all modified files in the current director.

git status

The git status command displays the current status of your repository. It shows which files have been modified, staged, or untracked. This command is helpful for understanding the state of your project.

git log

The git log command shows a chronological list of commits in the repository. It displays information such as the commit hash, author, date, and commit message. Use git log --oneline for a more concise view.

git pull [remote][branch]

The git pull command fetches and merges changes from a remote repository into your local branch. It is used to update your local branch with the latest changes made by others. Note that you’d need to specify the remote and branch to pull from.

git branch

The git branch command lists all branches in your repository. It also highlights the branch you are currently on. Use git branch [branch_name] to create a new branch.

git checkout [branch_name]

The git checkout command combines changes from one branch into another. It integrates the changes from the specified branch into the current branch. This is useful when you want to incorporate features or bug fixes from one branch into another.

git merge [branch]

The git merge command combines changes from one branch into another. It integrates the changes from the specified branch into the current branch. This is useful when you want to incorporate features or bug fixes from one branch into another.

git remote

The git remote command lists the remote repositories associated with your local repository. It shows their names, URL’s and other information. You can add new remotes using git remote add [name][url].

Conclusion

Having an understanding of these commands will greatly enhance your ability to manage and collaborate on projects effectively. It can also be convenient to have these in one place so as to access them with ease when you need to.

Thanks for reading. Happy Coding!