0% found this document useful (0 votes)
122 views

Git Commands

Git is a version control system used to track changes to files and coordinate work on projects. The document lists common Git commands used to initialize and configure a local repository, commit changes, work with remote repositories, and manage branches and merges.

Uploaded by

messi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
122 views

Git Commands

Git is a version control system used to track changes to files and coordinate work on projects. The document lists common Git commands used to initialize and configure a local repository, commit changes, work with remote repositories, and manage branches and merges.

Uploaded by

messi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Git task Notes Git commands

Configure the author


name and email address
to be used with your
commits. git config --global user.name
"Sam Smith"
Tell Git who you are
Note that Git strips
some characters (for git config --global us
example trailing
periods) from
user.name.
Create a new local
git init
repository
Create a working copy of a
Check out a repository git clone /path/to/repository
local repository:
git clone
For a remote server, use: username@host:/path/to/repository
git add <filename>
Add one or more files to
Add files
staging (index): git add *
Commit changes to head
Commit (but not yet to the remote git commit -m "Commit message"
repository):
Commit any files you've
added with git add, and
also commit any files git commit -a
you've changed since
then:
Send changes to the
Push master branch of your git push origin master
remote repository:
List the files you've
changed and those you
Status git status
still need to add or
commit:
If you haven't connected
your local repository to a
Connect to a remote
remote server, add the git remote add origin <server>
repository
server to be able to push
to it:
List all currently
configured remote git remote -v
repositories:
Create a new branch and
Branches git checkout -b <branchname>
switch to it:
Switch from one branch to
git checkout <branchname>
another:
List all the branches in
your repo, and also tell
git branch
you what branch you're
currently in:
Delete the feature branch: git branch -d <branchname>
Push the branch to your
remote repository, so git push origin <branchname>
others can use it:
Push all branches to your
git push --all origin
remote repository:
Delete a branch on your
git push origin :<branchname>
remote repository:
Fetch and merge changes
Update from the remote
on the remote server to git pull
repository
your working directory:
To merge a different
branch into your active git merge <branchname>
branch:
View all the merge
conflicts: git diff

View the conflicts git diff --base <filename>


against the base file:
git diff <sourcebranch>
Preview changes, before <targetbranch>
merging:
After you have manually
resolved any conflicts, you git add <filename>
mark the changed file:
You can use tagging to
mark a significant
Tags git tag 1.0.0 <commitID>
changeset, such as a
release:
CommitId is the leading
characters of the
changeset ID, up to 10, git log
but must be unique. Get
the ID using:
Push all tags to remote
git push --tags origin
repository:
If you mess up, you can
replace the changes in
Undo local changes git checkout -- <filename>
your working tree with the
last content in head:
Changes already added
to the index, as well as
new files, will be kept.
Instead, to drop all your
local changes and
commits, fetch the latest git fetch origin
history from the server
and point your local git reset --hard origin/master
master branch at it, do
this:
Search the working
Search git grep "foo()"
directory for foo():

You might also like