Git/GitHub

Git/GitHub

Here are some basic Git commands that you can use to manage your code repository:

  • BASIC COMMANDS

  • use git help [command]

    Branches

  • Master - default branch

  • origin - default upstream branch

  • head - current branch

    create from existing files

  • git init: Initializes an empty Git repository in your current directory.

  • git clone [repo]: Creates a local copy of a remote Git repository.

  • git add [file]: Adds changes to the staging area, making them ready for a commit.

  • touch <file name> : touch is used to generate a new empty file or multiple files at once.

    Publish

  • git commit -m "message": Commits the changes to the repository with a commit message explaining what changes were made.

  • ls : Used to 'list' contents of the current working directory

  • git push: Uploads local repository content to a remote repository.

  • git pull: Downloads changes from a remote repository and incorporates them into your local repository.

  • git branch: Lists all branches in the current repository.

  • git branch [branch-name]: Creates a new branch with the given name.

  • git checkout [branch-name]: Switches to the specified branch.

  • git merge [branch]: Merges the specified branch into the current branch.

    View

  • git status: Shows the current state of the working directory and staging area.

  • git diff : runs a diff function on Git data sources

  • git log : used for exploring a repository's history

  • git blame : examine the contents of a file line by line and see when each line was last modified and who the author of the modifications was.

  • git branch : create, list, rename, and delete branches.

  • cat : cat command is used in the Linux operating system.

    used to concatenate the content of multiple files and write or print the content of any file.

  • git log : Git's basic tool for exploring a repository's history.

    Revert

  • git reset -hard (no undo) (reset to the last commit)

  • git revert branch undoing changes to a repository's commit history

  • git commmit --amend replace the previous commit

    conflicts

  • git giff [--base] : makes sense only for files that are in a conflicted state

  • git diff --ours : view the differences between the current branch and the branch you merged from

  • git diff --theirs : view the differences between the current branch and the branch you merged with, specifically focusing on the changes made in the merged branch.

  • git log --merges : display the commit history, specifically filtering and showing only the merge commits.

  • gitk --merge : provides a view of the commit history with a focus on merg commits.

These are some of the most commonly used Git commands. There are many more commands available for more specific tasks, but mastering these basic commands will go a long way toward helping you effectively manage your code repository with Git.